From 3dd0718939802835b24095844099f2984c5bcf7e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 14 May 2012 01:53:47 +0000 Subject: [PATCH] * Give an error at evaluation time if boot.loader.grub.device or boot.loader.grub.devices are not set, rather than complaining about it when it's too late. svn path=/nixos/trunk/; revision=34081 --- modules/installer/grub/grub.nix | 30 +++++++++-------- .../activation/switch-to-configuration.sh | 33 ++++++++----------- modules/system/activation/top-level.nix | 8 ++--- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/modules/installer/grub/grub.nix b/modules/installer/grub/grub.nix index 2d7393b7f870..97e5f12d048c 100644 --- a/modules/installer/grub/grub.nix +++ b/modules/installer/grub/grub.nix @@ -4,7 +4,9 @@ with pkgs.lib; let - grub = if config.boot.loader.grub.version == 1 then pkgs.grub else pkgs.grub2; + cfg = config.boot.loader.grub; + + grub = if cfg.version == 1 then pkgs.grub else pkgs.grub2; grubMenuBuilder = pkgs.substituteAll { src = ./grub-menu-builder.sh; @@ -48,15 +50,11 @@ in example = "/dev/hda"; type = with pkgs.lib.types; uniq string; description = '' - The device on which the boot loader, GRUB, will be - installed. If empty, GRUB won't be installed and it's your - responsibility to make the system bootable. The special - value nodev means that a GRUB boot menu - will be generated, but GRUB itself will not actually be - installed. - - To install grub into multiple devices look at - devices. + The device on which the GRUB boot loader will be installed. + The special value nodev means that a GRUB + boot menu will be generated, but GRUB itself will not + actually be installed. To install GRUB on multiple devices, + use boot.loader.grub.devices. ''; }; @@ -67,7 +65,7 @@ in description = '' The devices on which the boot loader, GRUB, will be installed. Can be used instead of device to - install grub into multiple devices (as softraid arrays holding /boot). + install grub into multiple devices (e.g., if as softraid arrays holding /boot). ''; }; @@ -197,7 +195,13 @@ in config = mkIf config.boot.loader.grub.enable { - system.build.menuBuilder = grubMenuBuilder; + boot.loader.grub.devices = optional (cfg.device != "") cfg.device; + + system.build = mkAssert (cfg.devices != []) + "You must set the ‘boot.loader.grub.device’ option to make the system bootable." + { menuBuilder = grubMenuBuilder; + inherit grub; + }; # Common attribute for boot loaders so only one of them can be # set at once. @@ -206,8 +210,6 @@ 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 b80945d115d1..da1471cf550b 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -26,28 +26,23 @@ if [ "$action" = "switch" -o "$action" = "boot" ]; then if [ "@bootLoader@" = "grub" ]; then - if [ -n '@grubDevices@' ]; then - mkdir -m 0700 -p /boot/grub - @menuBuilder@ @out@ + mkdir -m 0700 -p /boot/grub + @menuBuilder@ @out@ - # If the GRUB version has changed, then force a reinstall. - oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)" - newGrubVersion="@grubVersion@" + # 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 - for dev in @grubDevices@; do - if [ "$dev" != nodev ]; then - echo "installing the GRUB bootloader on $dev..." - @grub@/sbin/grub-install "$(readlink -f "$dev")" --no-floppy - fi - done - echo "$newGrubVersion" > /boot/grub/version - fi + if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then + for dev in @grubDevices@; do + if [ "$dev" != nodev ]; then + echo "installing the GRUB bootloader on $dev..." + @grub@/sbin/grub-install "$(readlink -f "$dev")" --no-floppy + fi + done + echo "$newGrubVersion" > /boot/grub/version + fi - else - echo "Warning: don't know how to make this configuration bootable; please set \`boot.loader.grub.device'." 1>&2 - fi - elif [ "@bootLoader@" = "generationsDir" ]; then @menuBuilder@ @out@ elif [ "@bootLoader@" = "efiBootStub" ]; then diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index 9557c12aca78..dedfb9a9bd86 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -186,12 +186,10 @@ let if config.boot.loader.grub.enable then (builtins.parseDrvName config.system.build.grub.name).version else ""; - grubDevices = with pkgs.lib; let + grubDevices = + let wrapQuotes = s: "\"" + s + "\""; - allDevices = [ config.boot.loader.grub.device ] ++ - config.boot.loader.grub.devices; - definedDevices = filter (s: s != "") allDevices; - in map wrapQuotes definedDevices; + in map wrapQuotes config.boot.loader.grub.devices; configurationName = config.boot.loader.grub.configurationName; };