git.iko.soy/typeable/nixpkgs
on master help sign in
nixos-install: re-enable --chroot option

I forgot to implement it the first time around. Whoops!

commit186c120bed6b5d4a9b1549159aa567005402000c authorDan Peebles <pumpkin@me.com> dateWed 30 Aug 2017, 21:57 (9 years ago) parentfb18203
1 file changed+29−6
nixos/modules/installer/tools/nixos-install.sh+29−6
nixos/modules/installer/tools/nixos-install.sh+29−6
@@ -102,7 +102,7 @@ fi
102102extraBuildFlags+=(--option "build-users-group" "$buildUsersGroup")
103103
104104# Inherit binary caches from the host
105−# TODO: will this still work with Nix 1.12 now that it has no perl? Probably not...
105+# TODO: will this still work with Nix 1.12 now that it has no perl? Probably not...
106106binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')"
107107extraBuildFlags+=(--option "binary-caches" "$binary_caches")
108108
@@ -110,8 +110,33 @@ nixpkgs="$(readlink -f "$(nix-instantiate --find-file nixpkgs)")"
110110export NIX_PATH="nixpkgs=$nixpkgs:nixos-config=$mountPoint/$NIXOS_CONFIG"
111111unset NIXOS_CONFIG
112112
113−# TODO: do I need to set NIX_SUBSTITUTERS here or is the --option binary-caches above enough?
114−
113+# These get created in nixos-prepare-root as well, but we want to make sure they're here in case we're
114+# running with --chroot. TODO: --chroot should just be split into a separate tool.
115+mkdir -m 0755 -p "$mountPoint/dev" "$mountPoint/proc" "$mountPoint/sys"
116+
117+# Set up some bind mounts we'll want regardless of chroot or not
118+mount --rbind /dev "$mountPoint/dev"
119+mount --rbind /proc "$mountPoint/proc"
120+mount --rbind /sys "$mountPoint/sys"
121+
122+# If we asked for a chroot, that means we're not actually installing anything (yeah I was confused too)
123+# and we just want to run a command in the context of a $mountPoint that we're assuming has already been
124+# set up by a previous nixos-install invocation. In that case we set up some remaining bind mounts and
125+# exec the requested command, skipping the rest of the installation procedure.
126+if [ -n "$runChroot" ]; then
127+ mount -t tmpfs -o "mode=0755" none $mountPoint/run
128+ rm -rf $mountPoint/var/run
129+ ln -s /run $mountPoint/var/run
130+ for f in /etc/resolv.conf /etc/hosts; do rm -f $mountPoint/$f; [ -f "$f" ] && cp -Lf $f $mountPoint/etc/; done
131+ for f in /etc/passwd /etc/group; do touch $mountPoint/$f; [ -f "$f" ] && mount --rbind -o ro $f $mountPoint/$f; done
132+
133+ if ! [ -L $mountPoint/nix/var/nix/profiles/system ]; then
134+ echo "$0: installation not finished; cannot chroot into installation directory"
135+ exit 1
136+ fi
137+ ln -s /nix/var/nix/profiles/system $mountPoint/run/current-system
138+ exec chroot $mountPoint "${chrootCommand[@]}"
139+fi
115140
116141# A place to drop temporary closures
117142trap "rm -rf $tmpdir" EXIT
@@ -145,9 +170,7 @@ nix-store --export $channel_root > $channel_closure
145170# nixos-prepare-root doesn't currently do anything with file ownership, so we set it up here instead
146171chown @root_uid@:@nixbld_gid@ $mountPoint/nix/store
147172
148−mount --rbind /dev $mountPoint/dev
149−mount --rbind /proc $mountPoint/proc
150−mount --rbind /sys $mountPoint/sys
173+
151174
152175# Grub needs an mtab.
153176ln -sfn /proc/mounts $mountPoint/etc/mtab