Merge pull request #211218 from ncfavier/fix-install-mount

nixos-install: only mount if root
This commit is contained in:
K900 2023-01-17 14:18:46 +03:00 committed by GitHub
commit 8fc3a1dcc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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