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
This commit is contained in:
zimbatm 2020-11-09 17:11:52 +01:00
parent cc47fa353c
commit cb765ad91c
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
2 changed files with 18 additions and 1 deletions

View File

@ -10,6 +10,16 @@ let
'';
});
in rec {
toStorePath = target:
# If a store path has been given, transform it to a string. And make sure
# to capture the store path in its context.
if lib.isStorePath target then
let path = toString target; in
builtins.appendContext path { "${path}" = { path = true; }; }
# Otherwise, add to the store. This takes care of appending the store path
# in the context automatically.
else "${target}";
arx = { archive, startup}:
stdenv.mkDerivation {
name = "arx";
@ -71,9 +81,13 @@ in rec {
};
makeStartup = { target, nixUserChrootFlags, nix-user-chroot', run }:
let
# Avoid re-adding a store path into the store
path = toStorePath target;
in
writeScript "startup" ''
#!/bin/sh
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${target}${run} "$@"
.${nix-user-chroot'}/bin/nix-user-chroot -n ./nix ${nixUserChrootFlags} -- ${path}${run} "$@"
'';
nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot, nixUserChrootFlags ? "" }:

View File

@ -8,6 +8,9 @@ Usage: $0 TARGET EXECUTABLE
Create a single-file bundle from the nixpkgs attribute "TARGET".
EXECUTABLE should be relative to the TARGET's output path.
The TARGET is either an attribute in nixpkgs, or an absolute path to the
store.
For example:
$ $0 hello /bin/hello