on master help sign in
Allow multiple targets in nix-bundle
commit1584ab8dc43ac850fec0e709da60b46bc33290e7 authorMatthew Bauer <mjbauer95@gmail.com> dateSat 29 Apr 2017, 19:53 (9 years ago) parent608f245
2 files changed+54−7
default.nix+33−4 nix-bundle.sh+21−3
default.nix+33−4
@@ -28,7 +28,7 @@ rec {
2828 };
2929
3030 # TODO: eventually should this go in nixpkgs?
31− nix-user-chroot = stdenv.mkDerivation {
31+ nix-user-chroot = stdenv.lib.makeOverridable stdenv.mkDerivation {
3232 name = "nix-user-chroot-2b144e";
3333 src = fetchFromGitHub {
3434 owner = "matthewbauer";
@@ -37,6 +37,7 @@ rec {
3737 sha256 = "16bmshhvk6941w04rx78i5a1305876qni2n2rvm7rkziz49j158n";
3838 };
3939
40+ # hack to use when /nix/store is not available
4041 postFixup = ''
4142 exe=$out/bin/nix-user-chroot
4243 patchelf \
@@ -46,8 +47,12 @@ rec {
4647 '';
4748
4849 installPhase = ''
50+ runHook preInstall
51+
4952 mkdir -p $out/bin/
5053 cp nix-user-chroot $out/bin/nix-user-chroot
54+
55+ runHook postInstall
5156 '';
5257 };
5358
@@ -59,9 +64,33 @@ rec {
5964 };
6065 };
6166
62− nix-bootstrap = { target, run }:
67+ nix-bootstrap = { target, extraTargets ? [], run, nix-user-chroot' ? nix-user-chroot }:
6368 makebootstrap {
64− startup = ''.${nix-user-chroot}/bin/nix-user-chroot ./nix ${target}${run} \$@'';
65− targets = [ nix-user-chroot target ];
69+ startup = ''.${nix-user-chroot'}/bin/nix-user-chroot ./nix ${target}${run} \$@'';
70+ targets = [ nix-user-chroot' target ] ++ extraTargets;
71+ };
72+
73+ # special case handling because of impurities in nix bootstrap
74+ # anything that needs Nix will have to have these setup before they can be run
75+ nix-bootstrap-nix = let
76+ nix-user-chroot' = nix-user-chroot.override {
77+ buildInputs = [ cacert gnutar bzip2 gzip coreutils ];
78+ makeFlags = [
79+ ''NIX_SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"''
80+ ''NIX_PATH="nixpkgs=https://github.com/matthewbauer/nixpkgs/archive/nix-bundle.tar.gz"''
81+ ''ENV_PATH="${stdenv.lib.makeBinPath [ coreutils gnutar bzip2 gzip bash ]}"''
82+ ];
83+ }; in { target, extraTargets ? [], run }: nix-bootstrap { inherit target extraTargets run nix-user-chroot'; };
84+
85+ # special case adding path to the environment before launch
86+ nix-bootstrap-path = let
87+ nix-user-chroot'' = targets: nix-user-chroot.override {
88+ buildInputs = targets;
89+ makeFlags = [
90+ ''ENV_PATH="${stdenv.lib.makeBinPath targets}"''
91+ ];
92+ }; in { target, extraTargets ? [], run }: nix-bootstrap {
93+ inherit target extraTargets run;
94+ nix-user-chroot' = nix-user-chroot'' extraTargets;
6695 };
6796}
nix-bundle.sh+21−3
@@ -19,12 +19,30 @@ EOF
1919 exit 1
2020fi
2121
22+nix_file=`dirname $0`/default.nix
23+
2224target="$1"
23−exec="$2"
25+shift
26+
27+extraTargets=
28+if [ "$#" -gt 1 ]; then
29+ while [ "$#" -gt 1 ]; do
30+ extraTargets="$extraTargets $1"
31+ shift
32+ done
33+fi
2434
25−nix_file=`dirname $0`/default.nix
35+exec="$1"
36+shift
37+
38+bootstrap=nix-bootstrap
39+if [ "$target" = "nix-bundle" ] || [ "$target" = "nixStable" ] || [ "$target" = "nixUnstable" ]; then
40+ bootstrap=nix-bootstrap-nix
41+elif ! [ -z "$extraTargets" ]; then
42+ bootstrap=nix-bootstrap-path
43+fi
2644
27−expr="with import <nixpkgs> {}; with import $nix_file {}; nix-bootstrap { target = $target; run = \"$exec\"; }"
45+expr="with import <nixpkgs> {}; with import $nix_file {}; $bootstrap { target = $target; extraTargets = [ $extraTargets ]; run = \"$exec\"; }"
2846
2947out=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E "$expr"))
3048