112 lines
2.5 KiB
Nix
112 lines
2.5 KiB
Nix
{ config, lib, pkgs, inputs, ... }:
|
|
|
|
let
|
|
pxeRoot = "/srv/pxe";
|
|
pxeBaseUrl = "http://192.168.2.247";
|
|
|
|
bootIpxe = pkgs.writeText "boot.ipxe" ''
|
|
#!ipxe
|
|
|
|
dhcp
|
|
echo Booting from PXE server...
|
|
chain ${pxeBaseUrl}/menu.ipxe
|
|
'';
|
|
|
|
autoexecIpxe = pkgs.writeText "autoexec.ipxe" ''
|
|
#!ipxe
|
|
|
|
dhcp
|
|
chain ${pxeBaseUrl}/boot.ipxe
|
|
'';
|
|
|
|
menuIpxe = pkgs.writeText "menu.ipxe" ''
|
|
#!ipxe
|
|
|
|
set base ${pxeBaseUrl}
|
|
|
|
menu PXE Boot Menu
|
|
item nixos NixOS Installer
|
|
item rescue Rescue Environment
|
|
item shell iPXE Shell
|
|
item reboot Reboot
|
|
|
|
choose target && goto ''${target}
|
|
|
|
:nixos
|
|
kernel ''${base}/nixos/bzImage ip=dhcp
|
|
initrd ''${base}/nixos/initrd
|
|
boot
|
|
|
|
:rescue
|
|
kernel ''${base}/rescue/vmlinuz ip=dhcp
|
|
initrd ''${base}/rescue/initrd
|
|
boot
|
|
|
|
:shell
|
|
shell
|
|
|
|
:reboot
|
|
reboot
|
|
'';
|
|
in
|
|
{
|
|
imports =
|
|
[
|
|
../../common/configuration.nix
|
|
../../modules/nix/cache-client.nix
|
|
../../modules/nix/remote-builder-client.nix
|
|
];
|
|
|
|
networking.hostName = "pxe-boot";
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
ipxe
|
|
];
|
|
|
|
services.nginx = {
|
|
enable = true;
|
|
|
|
virtualHosts."pxe-boot" = {
|
|
default = true;
|
|
root = pxeRoot;
|
|
locations."/" = {
|
|
extraConfig = ''
|
|
autoindex on;
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
# TFTP is only used to deliver the initial iPXE bootloader. After iPXE
|
|
# starts, all further assets are fetched via nginx over HTTP from /srv/pxe.
|
|
services.atftpd = {
|
|
enable = true;
|
|
root = "${pxeRoot}/boot";
|
|
extraOptions = [
|
|
"--verbose=5"
|
|
];
|
|
};
|
|
|
|
systemd.tmpfiles.rules = [
|
|
"d ${pxeRoot} 0755 root root -"
|
|
"d ${pxeRoot}/boot 0755 root root -"
|
|
"d ${pxeRoot}/nixos 0755 root root -"
|
|
"d ${pxeRoot}/ubuntu 0755 root root -"
|
|
"d ${pxeRoot}/rescue 0755 root root -"
|
|
"C+ ${pxeRoot}/boot.ipxe 0644 root root - ${bootIpxe}"
|
|
"C+ ${pxeRoot}/menu.ipxe 0644 root root - ${menuIpxe}"
|
|
"C+ ${pxeRoot}/boot/autoexec.ipxe 0644 root root - ${autoexecIpxe}"
|
|
"C+ ${pxeRoot}/boot/boot.ipxe 0644 root root - ${bootIpxe}"
|
|
"C+ ${pxeRoot}/boot/menu.ipxe 0644 root root - ${menuIpxe}"
|
|
"C+ ${pxeRoot}/boot/ipxe.efi 0644 root root - ${pkgs.ipxe}/ipxe.efi"
|
|
"C+ ${pxeRoot}/boot/undionly.kpxe 0644 root root - ${pkgs.ipxe}/undionly.kpxe"
|
|
];
|
|
|
|
services.openssh.settings.PermitRootLogin = "yes";
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
networking.firewall.allowedUDPPorts = [ 69 ];
|
|
|
|
system.stateVersion = "25.05";
|
|
}
|