summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Peebles <copumpkin@users.noreply.github.com>2017-09-26 12:23:19 -0700
committerGitHub <noreply@github.com>2017-09-26 12:23:19 -0700
commit79d8ccf4f0787b1849153f813cd0a9e6b84d23a1 (patch)
tree05a4e4c17c560eb263b456ace188f1b267a6e240
parent0ddca0715acd90491db27286adb9b459e24403f8 (diff)
parent186c120bed6b5d4a9b1549159aa567005402000c (diff)
downloadnixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.tar
nixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.tar.gz
nixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.tar.bz2
nixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.tar.lz
nixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.tar.xz
nixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.tar.zst
nixpkgs-79d8ccf4f0787b1849153f813cd0a9e6b84d23a1.zip
Merge pull request #28777 from copumpkin/installer-chroot
nixos-install: re-enable --chroot option
-rw-r--r--nixos/modules/installer/tools/nixos-install.sh35
1 files changed, 29 insertions, 6 deletions
diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh
index 79ed18c923c..f994d5b4bde 100644
--- a/nixos/modules/installer/tools/nixos-install.sh
+++ b/nixos/modules/installer/tools/nixos-install.sh
@@ -102,7 +102,7 @@ fi
 extraBuildFlags+=(--option "build-users-group" "$buildUsersGroup")
 
 # Inherit binary caches from the host
-# TODO: will this still work with Nix 1.12 now that it has no perl? Probably not... 
+# TODO: will this still work with Nix 1.12 now that it has no perl? Probably not...
 binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')"
 extraBuildFlags+=(--option "binary-caches" "$binary_caches")
 
@@ -113,8 +113,33 @@ if [[ -z "$closure" ]]; then
 fi
 unset NIXOS_CONFIG
 
-# TODO: do I need to set NIX_SUBSTITUTERS here or is the --option binary-caches above enough?
-
+# These get created in nixos-prepare-root as well, but we want to make sure they're here in case we're
+# running with --chroot. TODO: --chroot should just be split into a separate tool.
+mkdir -m 0755 -p "$mountPoint/dev" "$mountPoint/proc" "$mountPoint/sys"
+
+# Set up some bind mounts we'll want regardless of chroot or not
+mount --rbind /dev "$mountPoint/dev"
+mount --rbind /proc "$mountPoint/proc"
+mount --rbind /sys "$mountPoint/sys"
+
+# If we asked for a chroot, that means we're not actually installing anything (yeah I was confused too)
+# and we just want to run a command in the context of a $mountPoint that we're assuming has already been
+# set up by a previous nixos-install invocation. In that case we set up some remaining bind mounts and
+# exec the requested command, skipping the rest of the installation procedure.
+if [ -n "$runChroot" ]; then
+    mount -t tmpfs -o "mode=0755" none $mountPoint/run
+    rm -rf $mountPoint/var/run
+    ln -s /run $mountPoint/var/run
+    for f in /etc/resolv.conf /etc/hosts; do rm -f $mountPoint/$f; [ -f "$f" ] && cp -Lf $f $mountPoint/etc/; done
+    for f in /etc/passwd /etc/group;      do touch $mountPoint/$f; [ -f "$f" ] && mount --rbind -o ro $f $mountPoint/$f; done
+
+    if ! [ -L $mountPoint/nix/var/nix/profiles/system ]; then
+        echo "$0: installation not finished; cannot chroot into installation directory"
+        exit 1
+    fi
+    ln -s /nix/var/nix/profiles/system $mountPoint/run/current-system
+    exec chroot $mountPoint "${chrootCommand[@]}"
+fi
 
 # A place to drop temporary closures
 trap "rm -rf $tmpdir" EXIT
@@ -153,9 +178,7 @@ nix-store --export $channel_root > $channel_closure
 # nixos-prepare-root doesn't currently do anything with file ownership, so we set it up here instead
 chown @root_uid@:@nixbld_gid@ $mountPoint/nix/store
 
-mount --rbind /dev $mountPoint/dev
-mount --rbind /proc $mountPoint/proc
-mount --rbind /sys $mountPoint/sys
+
 
 # Grub needs an mtab.
 ln -sfn /proc/mounts $mountPoint/etc/mtab