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