at master 1.3 kB view raw
1# This module adds a scripted iPXE entry to the GRUB boot menu. 2 3{ 4 config, 5 lib, 6 pkgs, 7 ... 8}: 9 10with lib; 11 12let 13 scripts = builtins.attrNames config.boot.loader.grub.ipxe; 14 15 grubEntry = name: '' 16 menuentry "iPXE - ${name}" { 17 linux16 @bootRoot@/ipxe.lkrn 18 initrd16 @bootRoot@/${name}.ipxe 19 } 20 21 ''; 22 23 scriptFile = 24 name: 25 let 26 value = builtins.getAttr name config.boot.loader.grub.ipxe; 27 in 28 if builtins.typeOf value == "path" then value else builtins.toFile "${name}.ipxe" value; 29in 30{ 31 options = { 32 boot.loader.grub.ipxe = mkOption { 33 type = types.attrsOf (types.either types.path types.str); 34 description = '' 35 Set of iPXE scripts available for 36 booting from the GRUB boot menu. 37 ''; 38 default = { }; 39 example = literalExpression '' 40 { demo = ''' 41 #!ipxe 42 dhcp 43 chain http://boot.ipxe.org/demo/boot.php 44 '''; 45 } 46 ''; 47 }; 48 }; 49 50 config = mkIf (builtins.length scripts != 0) { 51 52 boot.loader.grub.extraEntries = toString (map grubEntry scripts); 53 54 boot.loader.grub.extraFiles = { 55 "ipxe.lkrn" = "${pkgs.ipxe}/ipxe.lkrn"; 56 } 57 // builtins.listToAttrs ( 58 map (name: { 59 name = name + ".ipxe"; 60 value = scriptFile name; 61 }) scripts 62 ); 63 }; 64 65}