@@ -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}