diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-05-09 00:25:05 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-05-09 00:52:02 +0200 |
commit | 3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc (patch) | |
tree | c6b8f911e3c994734bdf10497010694ab5242ca6 /nixos/modules/installer | |
parent | 4fc151b5a3c749833554379a96bd87676f6c5740 (diff) | |
download | nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.tar nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.tar.gz nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.tar.bz2 nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.tar.lz nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.tar.xz nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.tar.zst nixlib-3ef8d6ad5c33a0bc9d0350155c19cac757ca16dc.zip |
nixos-install: Add operation --chroot
"nixos-install --chroot" runs a command (by default a login shell) in a chroot inside the NixOS installation in /mnt. This might useful for poking around a new installation.
Diffstat (limited to 'nixos/modules/installer')
-rw-r--r-- | nixos/modules/installer/tools/nixos-install.sh | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/nixos/modules/installer/tools/nixos-install.sh b/nixos/modules/installer/tools/nixos-install.sh index e708521c93f6..0ada85a26e2f 100644 --- a/nixos/modules/installer/tools/nixos-install.sh +++ b/nixos/modules/installer/tools/nixos-install.sh @@ -20,6 +20,7 @@ fi # Parse the command line for the -I flag extraBuildFlags=() +chrootCommand=(/run/current-system/sw/bin/bash) while [ "$#" -gt 0 ]; do i="$1"; shift 1 @@ -32,6 +33,11 @@ while [ "$#" -gt 0 ]; do --show-trace) extraBuildFlags+=("$i") ;; + --chroot) + runChroot=1 + chrootCommand=("$@") + break + ;; --help) exec man nixos-install exit 1 @@ -50,10 +56,6 @@ if test -z "$mountPoint"; then mountPoint=/mnt fi -if test -z "$NIXOS_CONFIG"; then - NIXOS_CONFIG=/etc/nixos/configuration.nix -fi - if ! test -e "$mountPoint"; then echo "mount point $mountPoint doesn't exist" exit 1 @@ -64,15 +66,8 @@ if ! grep -F -q " $mountPoint " /proc/mounts; then exit 1 fi -if ! test -e "$mountPoint/$NIXOS_CONFIG"; then - echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist" - exit 1 -fi - -# Mount some stuff in the target root directory. We bind-mount /etc -# into the chroot because we need networking and the nixbld user -# accounts in /etc/passwd. But we do need the target's /etc/nixos. +# Mount some stuff in the target root directory. mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/etc $mountPoint/run mkdir -m 01777 -p $mountPoint/tmp mkdir -m 0755 -p $mountPoint/tmp/root @@ -81,12 +76,38 @@ mount --rbind /dev $mountPoint/dev mount --rbind /proc $mountPoint/proc mount --rbind /sys $mountPoint/sys mount --rbind / $mountPoint/tmp/root -mount --bind /etc $mountPoint/etc -mount --bind $mountPoint/tmp/root/$mountPoint/etc/nixos $mountPoint/etc/nixos mount -t tmpfs -o "mode=0755" none $mountPoint/run mount -t tmpfs -o "mode=0755" none $mountPoint/var/setuid-wrappers +if [ -n "$runChroot" ]; then + 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 + + +# Bind-mount /etc into the chroot because we need networking and the +# nixbld user accounts in /etc/passwd. But we do need the target's +# /etc/nixos. +mount --bind /etc $mountPoint/etc +mount --bind $mountPoint/tmp/root/$mountPoint/etc/nixos $mountPoint/etc/nixos + + +# Get the path of the NixOS configuration file. +if test -z "$NIXOS_CONFIG"; then + NIXOS_CONFIG=/etc/nixos/configuration.nix +fi + +if ! test -e "$mountPoint/$NIXOS_CONFIG"; then + echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist" + exit 1 +fi + + # Create the necessary Nix directories on the target device, if they # don't already exist. mkdir -m 0755 -p \ @@ -147,12 +168,6 @@ mkdir -m 0755 -p $mountPoint/bin ln -sf @shell@ $mountPoint/bin/sh -if test -n "$NIXOS_PREPARE_CHROOT_ONLY"; then - echo "User requested only to prepare chroot. Exiting." - exit 0 -fi - - # Make the build below copy paths from the CD if possible. Note that # /tmp/root in the chroot is the root of the CD. export NIX_OTHER_STORES=/tmp/root/nix:$NIX_OTHER_STORES |