on master help sign in
fixes #68

The logic wasn't quite right in #67. I also added a ./test.sh to check for both use-cases.

commit33b7756441ba0cc9ae32c7c56c03e4fb528a5871 authorzimbatm <zimbatm@zimbatm.com> dateSun 29 Nov 2020, 13:28 (6 years ago) parentc5f2dfc
2 files changed+14−5
default.nix+4−5 test.sh+10
default.nix+4−5
@@ -11,11 +11,10 @@ let
1111 });
1212in rec {
1313 toStorePath = target:
14− # If a store path has been given, transform it to a string. And make sure
15− # to capture the store path in its context.
16− if lib.isStorePath target then
17− let path = toString target; in
18− builtins.appendContext path { "${path}" = { path = true; }; }
14+ # If a store path has been given but is a string, add the missing context
15+ # to it so it will be propagated properly as a build input.
16+ if builtins.isString target && lib.isStorePath target then
17+ builtins.appendContext target { "${target}" = { path = true; }; }
1918 # Otherwise, add to the store. This takes care of appending the store path
2019 # in the context automatically.
2120 else "${target}";
test.shnew file+10
@@ -0,0 +1,10 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+export NIX_PATH=channel:nixos-20.09
4+
5+echo "Test with attribute name"
6+./nix-bundle.sh hello /bin/hello
7+
8+echo "Test with store path"
9+out=$(nix-build --no-out-link --expr '(import <nixpkgs> {})' -A hello)
10+./nix-bundle.sh "$out" /bin/hello