From d210f30fa75fe6a06d5292f30251b8896d5ba0f6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Jun 2013 14:05:07 +0200 Subject: [PATCH] Omit GRUB if boot.loader.grub.device is set to "nodev" If we only need to generate a GRUB boot menu, we don't need GRUB itself. This cuts 38 MiB from EC2 system closures (in particular because it gets rid of the need for the 32-bit Glibc). --- modules/system/boot/loader/grub/grub.nix | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/system/boot/loader/grub/grub.nix b/modules/system/boot/loader/grub/grub.nix index 490502c5a36..1552d2cb102 100644 --- a/modules/system/boot/loader/grub/grub.nix +++ b/modules/system/boot/loader/grub/grub.nix @@ -6,7 +6,14 @@ let cfg = config.boot.loader.grub; - grub = if cfg.version == 1 then pkgs.grub else pkgs.grub2; + realGrub = if cfg.version == 1 then pkgs.grub else pkgs.grub2; + + grub = + # Don't include GRUB if we're only generating a GRUB menu (e.g., + # in EC2 instances). + if cfg.devices == ["nodev"] + then null + else realGrub; f = x: if x == null then "" else "" + x; @@ -14,8 +21,8 @@ let { splashImage = f config.boot.loader.grub.splashImage; grub = f grub; shell = "${pkgs.stdenv.shell}"; - fullVersion = (builtins.parseDrvName config.system.build.grub.name).version; - inherit (config.boot.loader.grub) + fullVersion = (builtins.parseDrvName realGrub.name).version; + inherit (cfg) version extraConfig extraPerEntryConfig extraEntries extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels timeout default devices; @@ -141,7 +148,7 @@ in splashImage = mkOption { default = - if config.boot.loader.grub.version == 1 + if cfg.version == 1 then pkgs.fetchurl { url = http://www.gnome-look.org/CONTENT/content-files/36909-soft-tux.xpm.gz; sha256 = "14kqdx2lfqvh40h6fjjzqgff1mwk74dmbjvmqphi6azzra7z8d59"; @@ -196,7 +203,7 @@ in ###### implementation - config = mkIf config.boot.loader.grub.enable { + config = mkIf cfg.enable { boot.loader.grub.devices = optional (cfg.device != "") cfg.device; @@ -212,7 +219,7 @@ in # set at once. system.boot.loader.id = "grub"; - environment.systemPackages = mkIf config.boot.loader.grub.enable [ grub ]; + environment.systemPackages = [ grub ]; };