From f44d27a96c6ff7c12a6c85a2d7d2069070f550c1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Nov 2012 22:53:57 +0100 Subject: [PATCH] Make the installer work on systemd Systemd mounts the root filesystem as a shared subtree, which breaks recursive bind mounts. --- modules/installer/tools/nixos-install.sh | 37 +++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/modules/installer/tools/nixos-install.sh b/modules/installer/tools/nixos-install.sh index 4e89770cce5..4d3d3db0861 100644 --- a/modules/installer/tools/nixos-install.sh +++ b/modules/installer/tools/nixos-install.sh @@ -17,7 +17,7 @@ if test -z "$mountPoint"; then fi if test -z "$NIXOS_CONFIG"; then - NIXOS_CONFIG=/mnt/etc/nixos/configuration.nix + NIXOS_CONFIG=/etc/nixos/configuration.nix fi if ! test -e "$mountPoint"; then @@ -30,7 +30,7 @@ if ! grep -F -q " $mountPoint " /proc/mounts; then exit 1 fi -if ! test -e "$NIXOS_CONFIG"; then +if ! test -e "$mountPoint/$NIXOS_CONFIG"; then echo "configuration file $NIXOS_CONFIG doesn't exist" exit 1 fi @@ -47,21 +47,30 @@ 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. -mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/mnt $mountPoint/etc -mount --rbind /dev $mountPoint/dev -mount --rbind /proc $mountPoint/proc -mount --rbind /sys $mountPoint/sys -mount --rbind / $mountPoint/mnt +mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/mnt $mountPoint/mnt2 $mountPoint/etc /etc/nixos +mount --make-private / # systemd makes / shared, which is annoying +mount --bind / $mountPoint/mnt +mount --bind /nix/store $mountPoint/mnt/nix/store +mount --bind /dev $mountPoint/dev +mount --bind /dev/shm $mountPoint/dev/shm +mount --bind /proc $mountPoint/proc +mount --bind /sys $mountPoint/sys +mount --bind $mountPoint/etc/nixos $mountPoint/mnt2 mount --bind /etc $mountPoint/etc -mount --bind $mountPoint/mnt/$mountPoint/etc/nixos $mountPoint/etc/nixos +mount --bind $mountPoint/mnt2 $mountPoint/etc/nixos cleanup() { set +e - umount -l $mountPoint/mnt - umount -l $mountPoint/dev - umount -l $mountPoint/proc - umount -l $mountPoint/sys - mountpoint -q $mountPoint/etc && umount -l $mountPoint/etc + mountpoint -q $mountPoint/etc/nixos && umount $mountPoint/etc/nixos + mountpoint -q $mountPoint/etc && umount $mountPoint/etc + umount $mountPoint/mnt2 + umount $mountPoint/sys + umount $mountPoint/proc + umount $mountPoint/dev/shm + umount $mountPoint/dev + umount $mountPoint/mnt/nix/store + umount $mountPoint/mnt + rmdir $mountPoint/mnt $mountPoint/mnt2 } trap "cleanup" EXIT @@ -151,7 +160,7 @@ srcs=$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-nam # Build the specified Nix expression in the target store and install # it into the system configuration profile. echo "building the system configuration..." -NIX_PATH="/mnt$srcs/nixos:nixos-config=/mnt$NIXOS_CONFIG" NIXOS_CONFIG= \ +NIX_PATH="/mnt$srcs/nixos:nixos-config=$NIXOS_CONFIG" NIXOS_CONFIG= \ chroot $mountPoint @nix@/bin/nix-env \ -p /nix/var/nix/profiles/system -f '' --set -A system --show-trace