on master help sign in
support store paths

Allow to pass a store path as a target. This is useful when combining nix-bundle with the output of another build. Eg: nix-bundle.sh $(nix-build "<nixpkgs>" -A hello) /bin/hello

commitcb765ad91c887c29af35d167dcb1332a068a97e0 authorzimbatm <zimbatm@zimbatm.com> dateMon 9 Nov 2020, 17:11 (6 years ago) parentcc47fa3
2 files changed+18−1
default.nix+15−1 nix-bundle.sh+3
default.nix+15−1
@@ -10,6 +10,16 @@ let
1010 '';
1111 });
1212in rec {
13+ 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; }; }
19+ # Otherwise, add to the store. This takes care of appending the store path
20+ # in the context automatically.
21+ else "${target}";
22+
1323 arx = { archive, startup}:
1424 stdenv.mkDerivation {
1525 name = "arx";
@@ -71,9 +81,13 @@ in rec {
7181 };
7282
7383 makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
84+ let
85+ # Avoid re-adding a store path into the store
86+ path = toStorePath target;
87+ in
7488 writeScript "startup" ''
7589 #!/bin/sh
76− .${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} "$@"
90+ .${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
7791 '';
7892
7993 nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:
nix-bundle.sh+3
@@ -8,6 +8,9 @@ Usage: $0 TARGET EXECUTABLE
88Create a single-file bundle from the nixpkgs attribute "TARGET".
99EXECUTABLE should be relative to the TARGET's output path.
1010
11+The TARGET is either an attribute in nixpkgs, or an absolute path to the
12+store.
13+
1114For example:
1215
1316$ $0 hello /bin/hello