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.
This commit is contained in:
Lluís Batlle i Rossell 2012-12-16 21:41:47 +01:00
parent 3e734ba695
commit 358239348a
3 changed files with 12 additions and 4 deletions

View File

@ -13,10 +13,11 @@ let
grubConfig = pkgs.writeText "grub-config.xml" (builtins.toXML grubConfig = pkgs.writeText "grub-config.xml" (builtins.toXML
{ splashImage = f config.boot.loader.grub.splashImage; { splashImage = f config.boot.loader.grub.splashImage;
grub = f grub; grub = f grub;
shell = "${pkgs.stdenv.shell}";
fullVersion = (builtins.parseDrvName config.system.build.grub.name).version; fullVersion = (builtins.parseDrvName config.system.build.grub.name).version;
inherit (config.boot.loader.grub) inherit (config.boot.loader.grub)
version extraConfig extraPerEntryConfig extraEntries version extraConfig extraPerEntryConfig extraEntries
extraEntriesBeforeNixOS configurationLimit copyKernels timeout extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels timeout
default devices; default devices;
}); });

View File

@ -30,6 +30,7 @@ sub writeFile {
my $grub = get("grub"); my $grub = get("grub");
my $grubVersion = int(get("version")); my $grubVersion = int(get("version"));
my $extraConfig = get("extraConfig"); my $extraConfig = get("extraConfig");
my $extraPrepareConfig = get("extraPrepareConfig");
my $extraPerEntryConfig = get("extraPerEntryConfig"); my $extraPerEntryConfig = get("extraPerEntryConfig");
my $extraEntries = get("extraEntries"); my $extraEntries = get("extraEntries");
my $extraEntriesBeforeNixOS = get("extraEntriesBeforeNixOS") eq "true"; my $extraEntriesBeforeNixOS = get("extraEntriesBeforeNixOS") eq "true";
@ -188,6 +189,8 @@ addEntry("NixOS - Default", $defaultConfig);
$conf .= "$extraEntries\n" unless $extraEntriesBeforeNixOS; $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. # Add entries for all previous generations of the system profile.
$conf .= "submenu \"NixOS - Old configurations\" {\n" if $grubVersion == 2; $conf .= "submenu \"NixOS - Old configurations\" {\n" if $grubVersion == 2;
@ -211,6 +214,10 @@ foreach my $link (@links) {
$conf .= "}\n" if $grubVersion == 2; $conf .= "}\n" if $grubVersion == 2;
# Run extraPrepareConfig in sh
if ($extraPrepareConfig ne "") {
system((get("shell"), "-c", $extraPrepareConfig));
}
# Atomically update the GRUB config. # Atomically update the GRUB config.
my $confFile = $grubVersion == 1 ? "/boot/grub/menu.lst" : "/boot/grub/grub.cfg"; my $confFile = $grubVersion == 1 ? "/boot/grub/menu.lst" : "/boot/grub/grub.cfg";

View File

@ -22,17 +22,17 @@ in
extraEntries = if config.boot.loader.grub.version == 2 then extraEntries = if config.boot.loader.grub.version == 2 then
'' ''
menuentry "${memtest86.name}" { menuentry "${memtest86.name}" {
linux16 $bootRoot/memtest.bin linux16 @bootRoot@/memtest.bin
} }
'' ''
else else
'' ''
menuentry "${memtest86.name}" menuentry "${memtest86.name}"
linux16 $bootRoot/memtest.bin linux16 @bootRoot@/memtest.bin
''; '';
extraPrepareConfig = extraPrepareConfig =
'' ''
cp ${memtest86}/memtest.bin /boot/memtest.bin; ${pkgs.coreutils}/bin/cp ${memtest86}/memtest.bin /boot/memtest.bin;
''; '';
}; };
} }