Make the installer work on systemd

Systemd mounts the root filesystem as a shared subtree, which breaks
recursive bind mounts.
This commit is contained in:
Eelco Dolstra 2012-11-15 22:53:57 +01:00
parent 08e6c0cb7c
commit f44d27a96c

View File

@ -17,7 +17,7 @@ if test -z "$mountPoint"; then
fi fi
if test -z "$NIXOS_CONFIG"; then if test -z "$NIXOS_CONFIG"; then
NIXOS_CONFIG=/mnt/etc/nixos/configuration.nix NIXOS_CONFIG=/etc/nixos/configuration.nix
fi fi
if ! test -e "$mountPoint"; then if ! test -e "$mountPoint"; then
@ -30,7 +30,7 @@ if ! grep -F -q " $mountPoint " /proc/mounts; then
exit 1 exit 1
fi fi
if ! test -e "$NIXOS_CONFIG"; then if ! test -e "$mountPoint/$NIXOS_CONFIG"; then
echo "configuration file $NIXOS_CONFIG doesn't exist" echo "configuration file $NIXOS_CONFIG doesn't exist"
exit 1 exit 1
fi fi
@ -47,21 +47,30 @@ fi
# Mount some stuff in the target root directory. We bind-mount /etc # Mount some stuff in the target root directory. We bind-mount /etc
# into the chroot because we need networking and the nixbld user # into the chroot because we need networking and the nixbld user
# accounts in /etc/passwd. But we do need the target's /etc/nixos. # 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 mkdir -m 0755 -p $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/mnt $mountPoint/mnt2 $mountPoint/etc /etc/nixos
mount --rbind /dev $mountPoint/dev mount --make-private / # systemd makes / shared, which is annoying
mount --rbind /proc $mountPoint/proc mount --bind / $mountPoint/mnt
mount --rbind /sys $mountPoint/sys mount --bind /nix/store $mountPoint/mnt/nix/store
mount --rbind / $mountPoint/mnt 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 /etc $mountPoint/etc
mount --bind $mountPoint/mnt/$mountPoint/etc/nixos $mountPoint/etc/nixos mount --bind $mountPoint/mnt2 $mountPoint/etc/nixos
cleanup() { cleanup() {
set +e set +e
umount -l $mountPoint/mnt mountpoint -q $mountPoint/etc/nixos && umount $mountPoint/etc/nixos
umount -l $mountPoint/dev mountpoint -q $mountPoint/etc && umount $mountPoint/etc
umount -l $mountPoint/proc umount $mountPoint/mnt2
umount -l $mountPoint/sys umount $mountPoint/sys
mountpoint -q $mountPoint/etc && umount -l $mountPoint/etc 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 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 # Build the specified Nix expression in the target store and install
# it into the system configuration profile. # it into the system configuration profile.
echo "building the system configuration..." 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 \ chroot $mountPoint @nix@/bin/nix-env \
-p /nix/var/nix/profiles/system -f '<nixos>' --set -A system --show-trace -p /nix/var/nix/profiles/system -f '<nixos>' --set -A system --show-trace