nixos: iPXE client for GRUB

fix bug in grub/install-grub.pl that would replace @bootRoot@ with an invalid string

Changed files
+67 -1
nixos
modules
system
boot
+1
nixos/modules/module-list.nix
···
./system/boot/loader/efi.nix
./system/boot/loader/generations-dir/generations-dir.nix
./system/boot/loader/grub/grub.nix
+
./system/boot/loader/grub/ipxe.nix
./system/boot/loader/grub/memtest.nix
./system/boot/loader/gummiboot/gummiboot.nix
./system/boot/loader/init-script/init-script.nix
+2 -1
nixos/modules/system/boot/loader/grub/install-grub.pl
···
$conf .= "$extraEntries\n" unless $extraEntriesBeforeNixOS;
+
my $grubBootPath = $grubBoot->path;
# extraEntries could refer to @bootRoot@, which we have to substitute
-
$conf =~ s/\@bootRoot\@/$grubBoot->path/g;
+
$conf =~ s/\@bootRoot\@/$grubBootPath/g;
# Emit submenus for all system profiles.
sub addProfile {
+64
nixos/modules/system/boot/loader/grub/ipxe.nix
···
+
# This module adds a scripted iPXE entry to the GRUB boot menu.
+
+
{ config, lib, pkgs, ... }:
+
+
with lib;
+
+
let
+
scripts = builtins.attrNames config.boot.loader.grub.ipxe;
+
+
grubEntry = name:
+
''
+
menuentry "iPXE - ${name}" {
+
linux16 @bootRoot@/ipxe.lkrn
+
initrd16 @bootRoot@/${name}.ipxe
+
}
+
+
'';
+
+
scriptFile = name:
+
let
+
value = builtins.getAttr name config.boot.loader.grub.ipxe;
+
in
+
if builtins.typeOf value == "path" then value
+
else builtins.toFile "${name}.ipxe" value;
+
in
+
{
+
options =
+
{ boot.loader.grub.ipxe = mkOption {
+
type = types.attrsOf (types.either types.path types.str);
+
description =
+
''
+
Set of iPXE scripts available for
+
booting from the GRUB boot menu.
+
'';
+
default = { };
+
example = literalExample ''
+
{ demo = '''
+
#!ipxe
+
dhcp
+
chain http://boot.ipxe.org/demo/boot.php
+
''';
+
};
+
'';
+
};
+
};
+
+
config = mkIf (builtins.length scripts != 0) {
+
+
boot.loader.grub.extraEntries =
+
if config.boot.loader.grub.version == 2 then
+
toString (map grubEntry scripts)
+
else
+
throw "iPXE is not supported with GRUB 1.";
+
+
boot.loader.grub.extraFiles =
+
{ "ipxe.lkrn" = "${pkgs.ipxe}/ipxe.lkrn"; }
+
//
+
builtins.listToAttrs ( map
+
(name: { name = name+".ipxe"; value = scriptFile name; })
+
scripts
+
);
+
};
+
+
}