at 17.09-beta 1.5 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 '' 32 Set of iPXE scripts available for 33 booting from the GRUB boot menu. 34 ''; 35 default = { }; 36 example = literalExample '' 37 { demo = ''' 38 #!ipxe 39 dhcp 40 chain http://boot.ipxe.org/demo/boot.php 41 '''; 42 } 43 ''; 44 }; 45 }; 46 47 config = mkIf (builtins.length scripts != 0) { 48 49 boot.loader.grub.extraEntries = 50 if config.boot.loader.grub.version == 2 then 51 toString (map grubEntry scripts) 52 else 53 throw "iPXE is not supported with GRUB 1."; 54 55 boot.loader.grub.extraFiles = 56 { "ipxe.lkrn" = "${pkgs.ipxe}/ipxe.lkrn"; } 57 // 58 builtins.listToAttrs ( map 59 (name: { name = name+".ipxe"; value = scriptFile name; }) 60 scripts 61 ); 62 }; 63 64}