From 358239348aea0f076069fcd60e94aa0610fe777f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Sun, 16 Dec 2012 21:41:47 +0100 Subject: [PATCH] making memtest grub entries work again I'm not any good at perl, and I only came up with this after many slow attempts. Any review welcome. But until this, memtest was broken, and extraPrepareConfig as well, in grub. --- modules/system/boot/loader/grub/grub.nix | 3 ++- modules/system/boot/loader/grub/install-grub.pl | 7 +++++++ modules/system/boot/loader/grub/memtest.nix | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/system/boot/loader/grub/grub.nix b/modules/system/boot/loader/grub/grub.nix index 0a9b374cc60c..70865c3c9338 100644 --- a/modules/system/boot/loader/grub/grub.nix +++ b/modules/system/boot/loader/grub/grub.nix @@ -13,10 +13,11 @@ let grubConfig = pkgs.writeText "grub-config.xml" (builtins.toXML { 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) version extraConfig extraPerEntryConfig extraEntries - extraEntriesBeforeNixOS configurationLimit copyKernels timeout + extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels timeout default devices; }); diff --git a/modules/system/boot/loader/grub/install-grub.pl b/modules/system/boot/loader/grub/install-grub.pl index 5e9f3b4efdad..0140a711d727 100644 --- a/modules/system/boot/loader/grub/install-grub.pl +++ b/modules/system/boot/loader/grub/install-grub.pl @@ -30,6 +30,7 @@ sub writeFile { my $grub = get("grub"); my $grubVersion = int(get("version")); my $extraConfig = get("extraConfig"); +my $extraPrepareConfig = get("extraPrepareConfig"); my $extraPerEntryConfig = get("extraPerEntryConfig"); my $extraEntries = get("extraEntries"); my $extraEntriesBeforeNixOS = get("extraEntriesBeforeNixOS") eq "true"; @@ -188,6 +189,8 @@ addEntry("NixOS - Default", $defaultConfig); $conf .= "$extraEntries\n" unless $extraEntriesBeforeNixOS; +# extraEntries could refer to @bootRoot@, which we have to substitute +$conf =~ s/\@bootRoot\@/$bootRoot/g; # Add entries for all previous generations of the system profile. $conf .= "submenu \"NixOS - Old configurations\" {\n" if $grubVersion == 2; @@ -211,6 +214,10 @@ foreach my $link (@links) { $conf .= "}\n" if $grubVersion == 2; +# Run extraPrepareConfig in sh +if ($extraPrepareConfig ne "") { + system((get("shell"), "-c", $extraPrepareConfig)); +} # Atomically update the GRUB config. my $confFile = $grubVersion == 1 ? "/boot/grub/menu.lst" : "/boot/grub/grub.cfg"; diff --git a/modules/system/boot/loader/grub/memtest.nix b/modules/system/boot/loader/grub/memtest.nix index 08eb8a1f41cb..4bd4b69101c9 100644 --- a/modules/system/boot/loader/grub/memtest.nix +++ b/modules/system/boot/loader/grub/memtest.nix @@ -22,17 +22,17 @@ in extraEntries = if config.boot.loader.grub.version == 2 then '' menuentry "${memtest86.name}" { - linux16 $bootRoot/memtest.bin + linux16 @bootRoot@/memtest.bin } '' else '' menuentry "${memtest86.name}" - linux16 $bootRoot/memtest.bin + linux16 @bootRoot@/memtest.bin ''; extraPrepareConfig = '' - cp ${memtest86}/memtest.bin /boot/memtest.bin; + ${pkgs.coreutils}/bin/cp ${memtest86}/memtest.bin /boot/memtest.bin; ''; }; }