Boot loader refactoring
- Renamed system.build.menuBuilder to system.build.installBootLoader. - ‘install-grub.pl’ (formerly grub-menu-builder.pl) now generates the GRUB menu *and* installs GRUB (if necessary). - ‘switch-to-configuration.sh’ has no boot loader specific knowledge anymore. It just calls installBootLoader.
This commit is contained in:
parent
1b743526bd
commit
b15e1fbb08
@ -168,7 +168,6 @@ in
|
|||||||
boot.loader.grub.enable = false;
|
boot.loader.grub.enable = false;
|
||||||
|
|
||||||
# !!! Hack - attributes expected by other modules.
|
# !!! Hack - attributes expected by other modules.
|
||||||
system.build.menuBuilder = "true";
|
|
||||||
system.boot.loader.kernelFile = "bzImage";
|
system.boot.loader.kernelFile = "bzImage";
|
||||||
environment.systemPackages = [ pkgs.grub2 ];
|
environment.systemPackages = [ pkgs.grub2 ];
|
||||||
|
|
||||||
|
@ -170,9 +170,6 @@ in
|
|||||||
boot.loader.generationsDir.enable = false;
|
boot.loader.generationsDir.enable = false;
|
||||||
system.boot.loader.kernelFile = "vmlinux";
|
system.boot.loader.kernelFile = "vmlinux";
|
||||||
|
|
||||||
# Needed for nixos to evaluate
|
|
||||||
system.build.menuBuilder = "true";
|
|
||||||
|
|
||||||
nixpkgs.config = {
|
nixpkgs.config = {
|
||||||
platform = pkgs.platforms.fuloong2f_n32;
|
platform = pkgs.platforms.fuloong2f_n32;
|
||||||
};
|
};
|
||||||
|
@ -177,9 +177,6 @@ in
|
|||||||
services.ttyBackgrounds.enable = false;
|
services.ttyBackgrounds.enable = false;
|
||||||
jobs.openssh.startOn = pkgs.lib.mkOverrideTemplate 50 {} "";
|
jobs.openssh.startOn = pkgs.lib.mkOverrideTemplate 50 {} "";
|
||||||
|
|
||||||
# Needed for nixos to evaluate
|
|
||||||
system.build.menuBuilder = "true";
|
|
||||||
|
|
||||||
nixpkgs.config = {
|
nixpkgs.config = {
|
||||||
platform = pkgs.platforms.sheevaplug;
|
platform = pkgs.platforms.sheevaplug;
|
||||||
};
|
};
|
||||||
|
@ -123,9 +123,7 @@ in
|
|||||||
system = mkIf (config.boot.loader.efiBootStub.enable && (assert
|
system = mkIf (config.boot.loader.efiBootStub.enable && (assert
|
||||||
(config.boot.kernelPackages.kernel.features ? efiBootStub &&
|
(config.boot.kernelPackages.kernel.features ? efiBootStub &&
|
||||||
config.boot.kernelPackages.kernel.features.efiBootStub); true)) {
|
config.boot.kernelPackages.kernel.features.efiBootStub); true)) {
|
||||||
build = {
|
build.installBootLoader = efiBootStubBuilder;
|
||||||
menuBuilder = efiBootStubBuilder;
|
|
||||||
};
|
|
||||||
boot.loader.id = "efiBootStub";
|
boot.loader.id = "efiBootStub";
|
||||||
boot.loader.kernelFile = platform.kernelTarget;
|
boot.loader.kernelFile = platform.kernelTarget;
|
||||||
};
|
};
|
||||||
|
@ -63,9 +63,7 @@ in
|
|||||||
];
|
];
|
||||||
|
|
||||||
system = mkIf config.boot.loader.generationsDir.enable {
|
system = mkIf config.boot.loader.generationsDir.enable {
|
||||||
build = {
|
build.installBootLoader = generationsDirBuilder;
|
||||||
menuBuilder = generationsDirBuilder;
|
|
||||||
};
|
|
||||||
boot.loader.id = "generationsDir";
|
boot.loader.id = "generationsDir";
|
||||||
boot.loader.kernelFile = platform.kernelTarget;
|
boot.loader.kernelFile = platform.kernelTarget;
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
|
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 configurationLimit copyKernels timeout
|
||||||
default;
|
default devices;
|
||||||
});
|
});
|
||||||
|
|
||||||
in
|
in
|
||||||
@ -199,9 +200,9 @@ in
|
|||||||
|
|
||||||
system.build = mkAssert (cfg.devices != [])
|
system.build = mkAssert (cfg.devices != [])
|
||||||
"You must set the ‘boot.loader.grub.device’ option to make the system bootable."
|
"You must set the ‘boot.loader.grub.device’ option to make the system bootable."
|
||||||
{ menuBuilder =
|
{ installBootLoader =
|
||||||
"PERL5LIB=${makePerlPath [ pkgs.perlPackages.XMLLibXML pkgs.perlPackages.XMLSAX ]} " +
|
"PERL5LIB=${makePerlPath [ pkgs.perlPackages.XMLLibXML pkgs.perlPackages.XMLSAX ]} " +
|
||||||
"${pkgs.perl}/bin/perl ${./grub-menu-builder.pl} ${grubConfig}";
|
"${pkgs.perl}/bin/perl ${./install-grub.pl} ${grubConfig}";
|
||||||
inherit grub;
|
inherit grub;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ use File::Basename;
|
|||||||
use File::Path;
|
use File::Path;
|
||||||
use File::stat;
|
use File::stat;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
use IO::File;
|
|
||||||
use POSIX;
|
use POSIX;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
|
|
||||||
@ -15,6 +14,19 @@ my $dom = XML::LibXML->load_xml(location => $ARGV[0]);
|
|||||||
|
|
||||||
sub get { my ($name) = @_; return $dom->findvalue("/expr/attrs/attr[\@name = '$name']/*/\@value"); }
|
sub get { my ($name) = @_; return $dom->findvalue("/expr/attrs/attr[\@name = '$name']/*/\@value"); }
|
||||||
|
|
||||||
|
sub readFile {
|
||||||
|
my ($fn) = @_; local $/ = undef;
|
||||||
|
open FILE, "<$fn" or return undef; my $s = <FILE>; close FILE;
|
||||||
|
local $/ = "\n"; chomp $s; return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub writeFile {
|
||||||
|
my ($fn, $s) = @_;
|
||||||
|
open FILE, ">$fn" or die "cannot create $fn: $!\n";
|
||||||
|
print FILE $s or die;
|
||||||
|
close FILE or die;
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
@ -151,8 +163,8 @@ sub addEntry {
|
|||||||
my $kernelParams =
|
my $kernelParams =
|
||||||
"systemConfig=" . Cwd::abs_path($path) . " " .
|
"systemConfig=" . Cwd::abs_path($path) . " " .
|
||||||
"init=" . Cwd::abs_path("$path/init") . " " .
|
"init=" . Cwd::abs_path("$path/init") . " " .
|
||||||
join " ", IO::File->new("$path/kernel-params")->getlines;
|
readFile("$path/kernel-params");
|
||||||
my $xenParams = $xen && -e "$path/xen-params" ? join " ", IO::File->new("$path/xen-params")->getlines : "";
|
my $xenParams = $xen && -e "$path/xen-params" ? readFile("$path/xen-params") : "";
|
||||||
|
|
||||||
if ($grubVersion == 1) {
|
if ($grubVersion == 1) {
|
||||||
$conf .= "title $name\n";
|
$conf .= "title $name\n";
|
||||||
@ -192,7 +204,7 @@ foreach my $link (@links) {
|
|||||||
my $date = strftime("%F", localtime(lstat($link)->mtime));
|
my $date = strftime("%F", localtime(lstat($link)->mtime));
|
||||||
my $version =
|
my $version =
|
||||||
-e "$link/nixos-version"
|
-e "$link/nixos-version"
|
||||||
? IO::File->new("$link/nixos-version")->getline
|
? readFile("$link/nixos-version")
|
||||||
: basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]);
|
: basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]);
|
||||||
addEntry("NixOS - Configuration " . nrFromGen($link) . " ($date - $version)", $link);
|
addEntry("NixOS - Configuration " . nrFromGen($link) . " ($date - $version)", $link);
|
||||||
}
|
}
|
||||||
@ -203,9 +215,7 @@ $conf .= "}\n" if $grubVersion == 2;
|
|||||||
# 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";
|
||||||
my $tmpFile = $confFile . ".tmp";
|
my $tmpFile = $confFile . ".tmp";
|
||||||
open CONF, ">$tmpFile" or die "cannot open $tmpFile for writing\n";
|
writeFile($tmpFile, $conf);
|
||||||
print CONF $conf or die;
|
|
||||||
close CONF;
|
|
||||||
rename $tmpFile, $confFile or die "cannot rename $tmpFile to $confFile\n";
|
rename $tmpFile, $confFile or die "cannot rename $tmpFile to $confFile\n";
|
||||||
|
|
||||||
|
|
||||||
@ -215,3 +225,18 @@ foreach my $fn (glob "/boot/kernels/*") {
|
|||||||
print STDERR "removing obsolete file $fn\n";
|
print STDERR "removing obsolete file $fn\n";
|
||||||
unlink $fn;
|
unlink $fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Install GRUB if the version changed from the last time we installed
|
||||||
|
# it. FIXME: shouldn't we reinstall if ‘devices’ changed?
|
||||||
|
my $prevVersion = readFile("/boot/grub/version") // "";
|
||||||
|
if (($ENV{'NIXOS_INSTALL_GRUB'} // "") eq "1" || get("fullVersion") ne $prevVersion) {
|
||||||
|
foreach my $dev ($dom->findnodes('/expr/attrs/attr[@name = "devices"]/list/string/@value')) {
|
||||||
|
$dev = $dev->findvalue(".") or die;
|
||||||
|
next if $dev eq "nodev";
|
||||||
|
print STDERR "installing the GRUB $grubVersion boot loader on $dev...\n";
|
||||||
|
system("$grub/sbin/grub-install", "--recheck", Cwd::abs_path($dev)) == 0
|
||||||
|
or die "$0: installation of GRUB on $dev failed\n";
|
||||||
|
}
|
||||||
|
writeFile("/boot/grub/version", get("fullVersion"));
|
||||||
|
}
|
@ -24,31 +24,7 @@ fi
|
|||||||
# Install or update the bootloader.
|
# Install or update the bootloader.
|
||||||
if [ "$action" = "switch" -o "$action" = "boot" ]; then
|
if [ "$action" = "switch" -o "$action" = "boot" ]; then
|
||||||
|
|
||||||
if [ "@bootLoader@" = "grub" ]; then
|
@installBootLoader@ @out@
|
||||||
|
|
||||||
@menuBuilder@ @out@
|
|
||||||
|
|
||||||
# If the GRUB version has changed, then force a reinstall.
|
|
||||||
oldGrubVersion="$(cat /boot/grub/version 2>/dev/null || true)"
|
|
||||||
newGrubVersion="@grubVersion@"
|
|
||||||
|
|
||||||
if [ "$NIXOS_INSTALL_GRUB" = 1 -o "$oldGrubVersion" != "$newGrubVersion" ]; then
|
|
||||||
for dev in @grubDevices@; do
|
|
||||||
if [ "$dev" != nodev ]; then
|
|
||||||
echo "installing the GRUB bootloader on $dev..."
|
|
||||||
@grub@/sbin/grub-install --recheck "$(readlink -f "$dev")" --no-floppy
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
echo "$newGrubVersion" > /boot/grub/version
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif [ "@bootLoader@" = "generationsDir" ]; then
|
|
||||||
@menuBuilder@ @out@
|
|
||||||
elif [ "@bootLoader@" = "efiBootStub" ]; then
|
|
||||||
@menuBuilder@ @out@
|
|
||||||
else
|
|
||||||
echo "Warning: don't know how to make this configuration bootable; please enable a boot loader." 1>&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "@initScriptBuilder@" ]; then
|
if [ -n "@initScriptBuilder@" ]; then
|
||||||
@initScriptBuilder@ @out@
|
@initScriptBuilder@ @out@
|
||||||
|
@ -101,9 +101,6 @@ let
|
|||||||
|
|
||||||
ln -s ${kernelPath} $out/kernel
|
ln -s ${kernelPath} $out/kernel
|
||||||
ln -s ${config.system.modulesTree} $out/kernel-modules
|
ln -s ${config.system.modulesTree} $out/kernel-modules
|
||||||
if [ -n "$grub" ]; then
|
|
||||||
ln -s $grub $out/grub
|
|
||||||
fi
|
|
||||||
|
|
||||||
ln -s ${config.system.build.initialRamdisk}/initrd $out/initrd
|
ln -s ${config.system.build.initialRamdisk}/initrd $out/initrd
|
||||||
|
|
||||||
@ -152,7 +149,9 @@ let
|
|||||||
inherit children;
|
inherit children;
|
||||||
kernelParams =
|
kernelParams =
|
||||||
config.boot.kernelParams ++ config.boot.extraKernelParams;
|
config.boot.kernelParams ++ config.boot.extraKernelParams;
|
||||||
menuBuilder = config.system.build.menuBuilder or "true";
|
installBootLoader =
|
||||||
|
config.system.build.installBootLoader
|
||||||
|
or "echo 'Warning: don't know how to make this configuration bootable; please enable a boot loader.' 1>&2; true";
|
||||||
initScriptBuilder = config.system.build.initScriptBuilder;
|
initScriptBuilder = config.system.build.initScriptBuilder;
|
||||||
activationScript = config.system.activationScripts.script;
|
activationScript = config.system.activationScripts.script;
|
||||||
nixosVersion = config.system.nixosVersion;
|
nixosVersion = config.system.nixosVersion;
|
||||||
@ -176,20 +175,6 @@ let
|
|||||||
config.system.build.upstart # for initctl
|
config.system.build.upstart # for initctl
|
||||||
];
|
];
|
||||||
|
|
||||||
# Boot loaders
|
|
||||||
bootLoader = config.system.boot.loader.id;
|
|
||||||
grub =
|
|
||||||
if config.boot.loader.grub.enable
|
|
||||||
then config.system.build.grub
|
|
||||||
else null;
|
|
||||||
grubVersion =
|
|
||||||
if config.boot.loader.grub.enable
|
|
||||||
then (builtins.parseDrvName config.system.build.grub.name).version
|
|
||||||
else "";
|
|
||||||
grubDevices =
|
|
||||||
let
|
|
||||||
wrapQuotes = s: "\"" + s + "\"";
|
|
||||||
in map wrapQuotes config.boot.loader.grub.devices;
|
|
||||||
configurationName = config.boot.loader.grub.configurationName;
|
configurationName = config.boot.loader.grub.configurationName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user