diff --git a/modules/installer/grub/grub-menu-builder.sh b/modules/installer/grub/grub-menu-builder.sh index f64aa837eb56..9db2bbfa41ca 100644 --- a/modules/installer/grub/grub-menu-builder.sh +++ b/modules/installer/grub/grub-menu-builder.sh @@ -5,36 +5,87 @@ shopt -s nullglob export PATH=/empty for i in @path@; do PATH=$PATH:$i/bin; done -default=$1 -if test -z "$1"; then - echo "Syntax: grub-menu-builder.sh " +if test $# -ne 1; then + echo "Usage: grub-menu-builder.sh DEFAULT-CONFIG" exit 1 fi +grubVersion="@version@" +defaultConfig="$1" bootDevice="@bootDevice@" if test -z "$bootDevice"; then bootDevice=/boot; fi - -echo "updating the GRUB menu..." +case "$grubVersion" in + 1|2) + echo "updating GRUB $grubVersion menu..." + ;; + *) + echo "Unsupported GRUB version \`$grubVersion'" >&2 + echo "Supported versions are \`1' (GRUB Legacy) and \`2' (GRUB 1.9x)." >&2 + exit 1 + ;; +esac -target=/boot/grub/menu.lst -tmp=$target.tmp +prologue() { + if test -n "@splashImage@"; then + splashLocation="@splashImage@" + if test "$grubVersion" -eq 1 ; then + # Splash images in /nix/store don't seem to work, so copy them. + cp -f $splashLocation /boot/background.xpm.gz + splashLocation="$bootDevice/background.xpm.gz" + fi + fi -cat > $tmp << GRUBEND + case "$grubVersion" in + 1) + cat > "$1" << GRUBEND # Automatically generated. DO NOT EDIT THIS FILE! default 0 timeout 5 GRUBEND - - -if test -n "@splashImage@"; then - splashLocation=@splashImage@ - # Splash images in /nix/store don't seem to work, so copy them. - cp -f $splashLocation /boot/background.xpm.gz - splashLocation="$bootDevice/background.xpm.gz" - echo "splashimage $splashLocation" >> $tmp + if test -n "@splashImage@"; then + echo "splashimage $splashLocation" >> "$1" + fi + ;; + 2) + cat > "$1" <> "$1" < /boot/nixos-grub-config < /boot/nixos-grub-config < /boot/nixos-grub-config <> $tmp << GRUBEND - + case "$grubVersion" in + 1) + cat >> "$tmp" << GRUBEND title $name kernel $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params) initrd $initrd GRUBEND + ;; + 2) + cat >> "$tmp" << GRUBEND +menuentry "$name" { + linux $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params) + initrd $initrd +} +GRUBEND + ;; + esac } @@ -146,7 +220,7 @@ if test -n "@extraEntriesBeforeNixOS@"; then echo "$extraEntries" >> $tmp fi -addEntry "NixOS - Default" $default "" +addEntry "NixOS - Default" $defaultConfig "" if test -z "@extraEntriesBeforeNixOS@"; then echo "$extraEntries" >> $tmp @@ -154,7 +228,7 @@ fi # Add all generations of the system profile to the menu, in reverse # (most recent to least recent) order. -for link in $((ls -d $default/fine-tune/* ) | sort -n); do +for link in $((ls -d $defaultConfig/fine-tune/* ) | sort -n); do date=$(stat --printf="%y\n" $link | sed 's/\..*//') addEntry "NixOS - variation" $link "" done diff --git a/modules/installer/grub/grub.nix b/modules/installer/grub/grub.nix index afeb947a2630..4394219a319f 100644 --- a/modules/installer/grub/grub.nix +++ b/modules/installer/grub/grub.nix @@ -7,10 +7,13 @@ let grubMenuBuilder = pkgs.substituteAll { src = ./grub-menu-builder.sh; isExecutable = true; + grub = if config.boot.loader.grub.version == 1 + then pkgs.grub + else pkgs.grub2; inherit (pkgs) bash; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; inherit (config.boot.loader.grub) copyKernels extraEntries extraEntriesBeforeNixOS - splashImage bootDevice configurationLimit; + splashImage bootDevice configurationLimit version; }; in @@ -30,6 +33,15 @@ in ''; }; + version = mkOption { + default = 1; + example = 2; + description = '' + The version of GRUB to use: 1 for GRUB Legacy + (versions 0.9x), or 2 for GRUB 2. + ''; + }; + device = mkOption { default = ""; example = "/dev/hda"; @@ -78,10 +90,17 @@ in }; splashImage = mkOption { - default = pkgs.fetchurl { - url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz; - sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59"; - }; + default = + if config.boot.loader.grub.version == 1 + then pkgs.fetchurl { + url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz; + sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59"; + } + # GRUB 1.97 doesn't support gzipped XPMs. + else pkgs.fetchurl { + url = http://www.gnu.org/graphics/winkler-gnu-blue.png; + sha256 = "0y8fvxalwxyid4k438k7c21bnv728qjsb92rqfapsmpv2bcj7f6k"; + }; example = null; description = " Background image used for Grub. It must be a 640x480, @@ -124,9 +143,16 @@ in # set at once. system.boot.loader.id = "grub"; system.boot.loader.kernelFile = "vmlinuz"; - - environment.systemPackages = mkIf config.boot.loader.grub.enable [ pkgs.grub ]; - + + environment.systemPackages = + mkIf config.boot.loader.grub.enable + (let version = config.boot.loader.grub.version; in + assert version != 1 -> version == 2; + + if version == 1 + then [ pkgs.grub ] + else [ pkgs.grub2 ]); + # and many other things that have to be moved inside this file. }; diff --git a/modules/system/activation/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh index 957bc124d7a6..802b57a31af0 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -27,6 +27,7 @@ if test "$action" = "switch" -o "$action" = "boot"; then mkdir -m 0700 -p /boot/grub @menuBuilder@ @out@ if test "$NIXOS_INSTALL_GRUB" = 1; then + echo "running \`@grub@/sbin/grub-install'..." @grub@/sbin/grub-install "@grubDevice@" --no-floppy --recheck fi else diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index 9fea447164b4..609b11dd3d6d 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -110,7 +110,12 @@ let # Boot loaders bootLoader = config.system.boot.loader.id; - grub = if config.boot.loader.grub.enable then pkgs.grub else null; + grub = + if config.boot.loader.grub.enable + then (if config.boot.loader.grub.version == 1 + then pkgs.grub + else pkgs.grub2) + else null; grubDevice = config.boot.loader.grub.device; configurationName = config.boot.loader.grub.configurationName; };