diff --git a/modules/installer/grub/grub.nix b/modules/installer/grub/grub.nix index 4bc36114f38..0939abd6e18 100644 --- a/modules/installer/grub/grub.nix +++ b/modules/installer/grub/grub.nix @@ -158,6 +158,8 @@ in environment.systemPackages = mkIf config.boot.loader.grub.enable [ grub ]; + system.build.grub = grub; + }; } diff --git a/modules/system/activation/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh index d4b70c3b379..86775ad62a8 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -21,26 +21,38 @@ EOF exit 1 fi -if test "$action" = "switch" -o "$action" = "boot"; then - if [ "@bootLoader@" == "grub" ]; then - if test -n "@grubDevice@"; then +# Install or update the bootloader. +if [ "$action" = "switch" -o "$action" = "boot" ]; then + + if [ "@bootLoader@" = "grub" ]; then + + if [ -n "@grubDevice@" ]; then mkdir -m 0700 -p /boot/grub @menuBuilder@ @out@ - if test "$NIXOS_INSTALL_GRUB" = 1; then - echo "running \`@grub@/sbin/grub-install'..." + + # If the GRUB version has changed, then force a reinstall. + oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)" + newGrubVersion="@grubVersion@" + + if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then + echo "installing the GRUB bootloader..." @grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck + echo "$newGrubVersion" > /boot/grub/version fi + else echo "Warning: don't know how to make this configuration bootable; please set \`boot.grubDevice'." 1>&2 fi - elif [ "@bootLoader@" == "generationsDir" ]; then + + elif [ "@bootLoader@" = "generationsDir" ]; then @menuBuilder@ @out@ else echo "Warning: don't know how to make this configuration bootable; please enable a boot loader." 1>&2 fi fi -if test "$action" = "switch" -o "$action" = "test"; then +# Activate the new configuration. +if [ "$action" = "switch" -o "$action" = "test" ]; then oldVersion=$(cat /var/run/current-system/upstart-interface-version 2> /dev/null || echo 0) newVersion=$(cat @out@/upstart-interface-version 2> /dev/null || echo 0) diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index 6bae1616df1..d2c20e90929 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -122,10 +122,12 @@ let bootLoader = config.system.boot.loader.id; grub = if config.boot.loader.grub.enable - then (if config.boot.loader.grub.version == 1 - then pkgs.grub - else pkgs.grub2) + then config.system.build.grub else null; + grubVersion = + if config.boot.loader.grub.enable + then (builtins.parseDrvName config.system.build.grub.name).version + else ""; grubDevice = config.boot.loader.grub.device; configurationName = config.boot.loader.grub.configurationName; };