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.
This commit is contained in:
parent
4fc151b5a3
commit
3ef8d6ad5c
@ -729,18 +729,22 @@ $ mount -o loop -t iso9660 ./result/iso/cd.iso /mnt/iso</screen>
|
|||||||
|
|
||||||
<title>Testing the installer</title>
|
<title>Testing the installer</title>
|
||||||
|
|
||||||
<para>Building, burning, and
|
<para>Building, burning, and booting from an installation CD is rather
|
||||||
booting from an installation CD is rather
|
|
||||||
tedious, so here is a quick way to see if the installer works
|
tedious, so here is a quick way to see if the installer works
|
||||||
properly:
|
properly:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-build -A config.system.build.nixos-install
|
$ nix-build -A config.system.build.nixos-install
|
||||||
$ dd if=/dev/zero of=diskimage seek=2G count=0 bs=1
|
$ mount -t tmpfs none /mnt
|
||||||
$ yes | mke2fs -j diskimage
|
|
||||||
$ mount -o loop diskimage /mnt
|
|
||||||
$ ./result/bin/nixos-install</screen>
|
$ ./result/bin/nixos-install</screen>
|
||||||
|
|
||||||
|
To start a login shell in the new NixOS installation in
|
||||||
|
<filename>/mnt</filename>:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ ./result/bin/nixos-install --chroot
|
||||||
|
</screen>
|
||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
@ -20,6 +20,7 @@ fi
|
|||||||
|
|
||||||
# Parse the command line for the -I flag
|
# Parse the command line for the -I flag
|
||||||
extraBuildFlags=()
|
extraBuildFlags=()
|
||||||
|
chrootCommand=(/run/current-system/sw/bin/bash)
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
i="$1"; shift 1
|
i="$1"; shift 1
|
||||||
@ -32,6 +33,11 @@ while [ "$#" -gt 0 ]; do
|
|||||||
--show-trace)
|
--show-trace)
|
||||||
extraBuildFlags+=("$i")
|
extraBuildFlags+=("$i")
|
||||||
;;
|
;;
|
||||||
|
--chroot)
|
||||||
|
runChroot=1
|
||||||
|
chrootCommand=("$@")
|
||||||
|
break
|
||||||
|
;;
|
||||||
--help)
|
--help)
|
||||||
exec man nixos-install
|
exec man nixos-install
|
||||||
exit 1
|
exit 1
|
||||||
@ -50,10 +56,6 @@ if test -z "$mountPoint"; then
|
|||||||
mountPoint=/mnt
|
mountPoint=/mnt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "$NIXOS_CONFIG"; then
|
|
||||||
NIXOS_CONFIG=/etc/nixos/configuration.nix
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! test -e "$mountPoint"; then
|
if ! test -e "$mountPoint"; then
|
||||||
echo "mount point $mountPoint doesn't exist"
|
echo "mount point $mountPoint doesn't exist"
|
||||||
exit 1
|
exit 1
|
||||||
@ -64,15 +66,8 @@ if ! grep -F -q " $mountPoint " /proc/mounts; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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.
|
||||||
# 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.
|
|
||||||
mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/etc $mountPoint/run
|
mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/etc $mountPoint/run
|
||||||
mkdir -m 01777 -p $mountPoint/tmp
|
mkdir -m 01777 -p $mountPoint/tmp
|
||||||
mkdir -m 0755 -p $mountPoint/tmp/root
|
mkdir -m 0755 -p $mountPoint/tmp/root
|
||||||
@ -81,12 +76,38 @@ mount --rbind /dev $mountPoint/dev
|
|||||||
mount --rbind /proc $mountPoint/proc
|
mount --rbind /proc $mountPoint/proc
|
||||||
mount --rbind /sys $mountPoint/sys
|
mount --rbind /sys $mountPoint/sys
|
||||||
mount --rbind / $mountPoint/tmp/root
|
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/run
|
||||||
mount -t tmpfs -o "mode=0755" none $mountPoint/var/setuid-wrappers
|
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
|
# Create the necessary Nix directories on the target device, if they
|
||||||
# don't already exist.
|
# don't already exist.
|
||||||
mkdir -m 0755 -p \
|
mkdir -m 0755 -p \
|
||||||
@ -147,12 +168,6 @@ mkdir -m 0755 -p $mountPoint/bin
|
|||||||
ln -sf @shell@ $mountPoint/bin/sh
|
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
|
# Make the build below copy paths from the CD if possible. Note that
|
||||||
# /tmp/root in the chroot is the root of the CD.
|
# /tmp/root in the chroot is the root of the CD.
|
||||||
export NIX_OTHER_STORES=/tmp/root/nix:$NIX_OTHER_STORES
|
export NIX_OTHER_STORES=/tmp/root/nix:$NIX_OTHER_STORES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user