diff --git a/modules/installer/grub/grub-menu-builder.sh b/modules/installer/grub/grub-menu-builder.sh index 8a99ca5f29d..f64aa837eb5 100644 --- a/modules/installer/grub/grub-menu-builder.sh +++ b/modules/installer/grub/grub-menu-builder.sh @@ -11,8 +11,8 @@ if test -z "$1"; then exit 1 fi -bootMount="@bootMount@" -if test -z "$bootMount"; then bootMount=/boot; fi +bootDevice="@bootDevice@" +if test -z "$bootDevice"; then bootDevice=/boot; fi echo "updating the GRUB menu..." @@ -28,11 +28,11 @@ timeout 5 GRUBEND -if test -n "@grubSplashImage@"; then - splashLocation=@grubSplashImage@ +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="$bootMount/background.xpm.gz" + splashLocation="$bootDevice/background.xpm.gz" echo "splashimage $splashLocation" >> $tmp fi @@ -40,7 +40,7 @@ fi configurationCounter=0 configurationLimit="@configurationLimit@" numAlienEntries=`cat < /boot/nixos-grub-config <> $tmp +if test -n "@extraEntriesBeforeNixOS@"; then + echo "$extraEntries" >> $tmp fi addEntry "NixOS - Default" $default "" -if test -z "@extraGrubEntriesBeforeNixos@"; then - echo "$extraGrubEntries" >> $tmp +if test -z "@extraEntriesBeforeNixOS@"; then + echo "$extraEntries" >> $tmp fi # Add all generations of the system profile to the menu, in reverse diff --git a/modules/installer/grub/grub.nix b/modules/installer/grub/grub.nix index 233c8fdc95e..1bfdda027b2 100644 --- a/modules/installer/grub/grub.nix +++ b/modules/installer/grub/grub.nix @@ -1,107 +1,7 @@ -{pkgs, config, ...}: +{ config, pkgs, ... }: -###### interface -let - inherit (pkgs.lib) mkOption mkIf; +with pkgs.lib; - options = { - boot = { - loader = { - grub = { - - enable = mkOption { - default = true; - description = '' - Whether to enable the GRUB boot loader. - ''; - }; - - grubDevice = mkOption { - default = ""; - example = "/dev/hda"; - 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. - "; - }; - - bootMount = mkOption { - default = ""; - example = "(hd0,0)"; - description = " - If the system partition may be wiped on reinstall, it is better - to have /boot on a small partition. To do it, we need to explain - to GRUB where the kernels live. Specify the partition here (in - GRUB notation. - "; - }; - - configurationName = mkOption { - default = ""; - example = "Stable 2.6.21"; - description = " - Grub entry name instead of default. - "; - }; - - extraGrubEntries = mkOption { - default = ""; - example = " - title Windows - chainloader (hd0,1)+1 - "; - description = " - Any additional entries you want added to the Grub boot menu. - "; - }; - - extraGrubEntriesBeforeNixos = mkOption { - default = false; - description = " - Wheter extraGrubEntries are put before the Nixos-default option - "; - }; - - grubSplashImage = mkOption { - default = pkgs.fetchurl { - url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz; - sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59"; - }; - example = null; - description = " - Background image used for Grub. It must be a 640x480, - 14-colour image in XPM format, optionally compressed with - gzip or bzip2. Set to - null to run Grub in text mode. - "; - }; - - configurationLimit = mkOption { - default = 100; - example = 120; - description = " - Maximum of configurations in boot menu. GRUB has problems when - there are too many entries. - "; - }; - - copyKernels = mkOption { - default = false; - description = " - Whether the Grub menu builder should copy kernels and initial - ramdisks to /boot. This is necessary when /nix is on a - different file system than /boot. - "; - }; - }; - }; - }; - }; -in - - -###### implementation let grubMenuBuilder = pkgs.substituteAll { @@ -109,31 +9,126 @@ let isExecutable = true; inherit (pkgs) bash; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; - inherit (config.boot.loader.grub) copyKernels extraGrubEntries extraGrubEntriesBeforeNixos - grubSplashImage bootMount configurationLimit; + inherit (config.boot.loader.grub) copyKernels extraEntries extraEntriesBeforeNixOS + splashImage bootDevice configurationLimit; }; + in { - require = [ - options - # config.system.build - # ../system/system-options.nix - ]; + ###### interface - system = mkIf config.boot.loader.grub.enable { - build = { - menuBuilder = grubMenuBuilder; + options = { + + boot.loader.grub = { + + enable = mkOption { + default = true; + description = '' + Whether to enable the GRUB boot loader. + ''; + }; + + device = mkOption { + default = ""; + example = "/dev/hda"; + 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. + "; + }; + + bootDevice = mkOption { + default = ""; + example = "(hd0,0)"; + description = " + If the system partition may be wiped on reinstall, it is better + to have /boot on a small partition. To do it, we need to explain + to GRUB where the kernels live. Specify the partition here (in + GRUB notation). + "; + }; + + configurationName = mkOption { + default = ""; + example = "Stable 2.6.21"; + description = " + Grub entry name instead of default. + "; + }; + + extraEntries = mkOption { + default = ""; + example = " + title Windows + chainloader (hd0,1)+1 + "; + description = " + Any additional entries you want added to the Grub boot menu. + "; + }; + + extraEntriesBeforeNixOS = mkOption { + default = false; + description = " + Whether extraEntries are included before the default option. + "; + }; + + splashImage = mkOption { + default = pkgs.fetchurl { + url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz; + sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59"; + }; + example = null; + description = " + Background image used for Grub. It must be a 640x480, + 14-colour image in XPM format, optionally compressed with + gzip or bzip2. Set to + null to run Grub in text mode. + "; + }; + + configurationLimit = mkOption { + default = 100; + example = 120; + description = " + Maximum of configurations in boot menu. GRUB has problems when + there are too many entries. + "; + }; + + copyKernels = mkOption { + default = false; + description = " + Whether the Grub menu builder should copy kernels and initial + ramdisks to /boot. This is necessary when /nix is on a + different file system than /boot. + "; + }; + }; - # Common attribute for boot loaders so only one of them can be - # set at once - boot.loader.id = "grub"; - boot.loader.kernelFile = "vmlinuz"; }; + - environment.extraPackages = mkIf config.boot.loader.grub.enable [ pkgs.grub ]; + ###### implementation - # and many other things that have to be moved inside this file. + config = mkIf config.boot.loader.grub.enable { + + system.build.menuBuilder = grubMenuBuilder; + + # Common attribute for boot loaders so only one of them can be + # set at once. + system.boot.loader.id = "grub"; + system.boot.loader.kernelFile = "vmlinuz"; + + environment.extraPackages = mkIf config.boot.loader.grub.enable [ pkgs.grub ]; + + # and many other things that have to be moved inside this file. + + }; + } diff --git a/modules/rename.nix b/modules/rename.nix index 950321105ca..c7847d7c5da 100644 --- a/modules/rename.nix +++ b/modules/rename.nix @@ -36,6 +36,12 @@ in zipModules ([] # ++ rename alias "services.xserver.slim.theme" to "services.xserver.displayManager.slim.theme" ++ rename obsolete "environment.extraPackages" to "environment.systemPackages" +# Old Grub-related options. +++ rename obsolete "boot.copyKernels" to "boot.loader.grub.copyKernels" +++ rename obsolete "boot.extraGrubEntries" to "boot.loader.grub.extraEntries" +++ rename obsolete "boot.extraGrubEntriesBeforeNixos" to "boot.loader.grub.extraEntriesBeforeNixOS" +++ rename obsolete "boot.grubDevice" to "boot.loader.grub.device" +++ rename obsolete "boot.bootMount" to "boot.loader.grub.bootDevice" ) # do not add renaming after this. diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index 992b988bc49..9fea447164b 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -46,7 +46,8 @@ let config.nesting.children; - systemBuilder = let + systemBuilder = + let kernelPath = "${config.boot.kernelPackages.kernel}/" + "${config.system.boot.loader.kernelFile}"; in @@ -110,7 +111,7 @@ let # Boot loaders bootLoader = config.system.boot.loader.id; grub = if config.boot.loader.grub.enable then pkgs.grub else null; - grubDevice = config.boot.loader.grub.grubDevice; + grubDevice = config.boot.loader.grub.device; configurationName = config.boot.loader.grub.configurationName; };