netboot.nix/pkgs/pxescript/default.nix

85 lines
2.2 KiB
Nix

{ stdenv, runCommand }:
{ config
, initrds ? {}
, pkgs
,
}:
let
cmdlineinitrds = builtins.concatStringsSep " " (builtins.map (name: "initrd=${name}") (builtins.attrNames initrds));
in
runCommand "netboot" {
autoexec-ipxe = ''
#!ipxe
dhcp
set path netboot
## next_server by default is the sever value from dhcp, uncomment to keep the value from dhcp
set next_server 172.16.1.6
chain http://''${next_server}/''${path}/netboot.ipxe
'';
netboot-ipxe = ''
#!ipxe
## Variables
set server 172.16.1.6
set path netboot
set source ''${uri}
##
:custom
clear custom_choice
menu NixOS netboot installer
item --gap Role Installers
item nix-netboot_1 ''${space} Boot NixOS
item option_two ''${space} Loading an ISO
item --gap Testing Tools (incomplete)
item option_three ''${space} Loads another custom sub menu
item option_four ''${space} This is option 4
choose custom_choice || goto custom_exit
echo ''${cls}
goto ''${custom_choice}
goto custom_exit
:nix_netboot_1
kernel ${pkgs.stdenv.hostPlatform.linux-kernel.target}
${builtins.concatStringsSep "\n" (builtins.attrValues (builtins.mapAttrs (name: path: "initrd ${name}") initrds))}
imgargs ${pkgs.stdenv.hostPlatform.linux-kernel.target} init=${config.system.build.toplevel}/init ${cmdlineinitrds} ${toString config.boot.kernelParams}
boot || goto custom_exit
:option_two
kernel memdisk iso raw
initrd http://mirror.mauer.tech/archlinux/iso/latest/archlinux-x86_64.iso
boot || goto custom_exit
:option_three
echo Chains into another menu...
chain custom1.ipxe || goto custom
:custom_exit
exit
'';
preferLocalBuild = true;
} ''
mkdir stage
cd stage
ln -s "${config.system.build.kernel}/${pkgs.stdenv.hostPlatform.linux-kernel.target}" ./
set -x
${builtins.concatStringsSep "\n"
(
builtins.attrValues
(
builtins.mapAttrs
(
name: path: ''
test -f "$(realpath "${path}")"
ln -s ${path} ./${name}
''
) initrds
)
)}
set +x
echo "$autoexec-ipxe" > autoexec.ipxe
echo "$netboot-ipxe" > netboot.ipxe
cd ..
mv stage $out
''