nixos-install: only mount if root

This commit is contained in:
Naïm Favier 2023-01-17 11:39:34 +01:00
parent 682381bf3f
commit cd4f1a1df5
No known key found for this signature in database
GPG key ID: 95AFCE8211908325

8
nixos/modules/installer/tools/nixos-install.sh Normal file → Executable file
View file

@ -193,9 +193,11 @@ touch "$mountPoint/etc/NIXOS"
# the root with `nixos-enter`.
# Without this the bootloader installation may fail due to options that
# contain paths referenced during evaluation, like initrd.secrets.
mount --rbind --mkdir "$mountPoint" "$mountPoint$mountPoint"
mount --make-rslave "$mountPoint$mountPoint"
trap 'umount -R "$mountPoint$mountPoint" && rmdir "$mountPoint$mountPoint"' EXIT
if (( EUID == 0 )); then
mount --rbind --mkdir "$mountPoint" "$mountPoint$mountPoint"
mount --make-rslave "$mountPoint$mountPoint"
trap 'umount -R "$mountPoint$mountPoint" && rmdir "$mountPoint$mountPoint"' EXIT
fi
# Switch to the new system configuration. This will install Grub with
# a menu default pointing at the kernel/initrd/etc of the new