From 9248259708bd6ade5e334a2cdfb29d2a20acb0dd Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 3 Oct 2022 17:15:36 +0200 Subject: ... --- hosts/vidhar/network/dhcp/default.nix | 58 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'hosts/vidhar/network/dhcp') diff --git a/hosts/vidhar/network/dhcp/default.nix b/hosts/vidhar/network/dhcp/default.nix index 067dc6d6..e14b15ac 100644 --- a/hosts/vidhar/network/dhcp/default.nix +++ b/hosts/vidhar/network/dhcp/default.nix @@ -1,4 +1,7 @@ { flake, config, pkgs, lib, ... }: + +with lib; + { config = { services.kea = { @@ -23,7 +26,7 @@ { name = "ipxe"; test = "option[77].hex == 'iPXE'"; next-server = "10.141.0.1"; - boot-file-name = "netboot.ipxe"; + boot-file-name = "installer-x86_64-linux/netboot.ipxe"; only-if-required = true; } { name = "uefi-64"; @@ -146,7 +149,7 @@ pools = [ { pool = "10.141.2.128 - 10.141.2.254"; } ]; reservations = []; } - ]; + ]; }; }; # dhcp6 = { @@ -195,16 +198,16 @@ }; systemd.services.kea-dhcp-ddns-server = { - preStart = let + preStart = let configLines = [ "" - ] ++ lib.mapAttrsToList (k: v: + ] ++ mapAttrsToList (k: v: "\"${k}\": ${builtins.toJSON v}" ) config.services.kea.dhcp-ddns.settings; config-template = pkgs.writeText "dhcp-ddns.conf" '' {"DhcpDdns": { - ${lib.concatStringsSep ",\n " configLines} + ${concatStringsSep ",\n " configLines} }} ''; in '' @@ -212,8 +215,8 @@ ''; serviceConfig = { - ExecStart = lib.mkForce '' - ${pkgs.kea}/bin/kea-dhcp-ddns -c "''${RUNTIME_DIRECTORY}/dhcp-ddns.conf" ${lib.escapeShellArgs config.services.kea.dhcp-ddns.extraArgs} + ExecStart = mkForce '' + ${pkgs.kea}/bin/kea-dhcp-ddns -c "''${RUNTIME_DIRECTORY}/dhcp-ddns.conf" ${escapeShellArgs config.services.kea.dhcp-ddns.extraArgs} ''; LoadCredential = [ "knot-tsig.json.frag:${config.sops.secrets."kea-knot-tsig.json.frag".path}" @@ -226,26 +229,53 @@ sopsFile = ./knot-tsig.json.frag; }; - systemd.services."installer-atftpd" = { - description = "TFTP Server for PXE Booting NixOS Installer"; + systemd.services."pxe-atftpd" = { + description = "TFTP Server for PXE Booting"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig.ExecStart = let - installerBuild = flake.nixosConfigurations.installer-x86_64-linux-netboot.config.system.build; ipxe = pkgs.ipxe.override { additionalTargets = { "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi"; }; }; - tftpRoot = pkgs.runCommandLocal "installer-netboot" {} '' + tftpRoot = pkgs.runCommandLocal "netboot" {} '' mkdir -p $out install -m 0444 -t $out \ - ${installerBuild.netbootRamdisk}/initrd \ - ${installerBuild.kernel}/bzImage \ - ${installerBuild.netbootIpxeScript}/netboot.ipxe \ ${ipxe}/ipxe.efi ${ipxe}/i386-ipxe.efi ${ipxe}/undionly.kpxe + + ${concatMapStringsSep "\n" (system: + let + installerBuild = (flake.nixosConfigurations.${"installer-${system}-nfsroot"}.extendModules { + modules = [ + ({ ... }: { config.nfsroot.storeDevice = "vidhar:nix-store"; }) + ]; + }).config.system.build; + in '' + mkdir -p $out/installer-${system} + install -m 0444 -t $out/installer-${system} \ + ${installerBuild.initialRamdisk}/initrd \ + ${installerBuild.kernel}/bzImage \ + ${installerBuild.netbootIpxeScript}/netboot.ipxe + '' + ) ["x86_64-linux"]} ''; in "${pkgs.atftp}/sbin/atftpd --daemon --no-fork --bind-address=10.141.0.1 ${tftpRoot}"; }; + + services.nfs.server = { + enable = true; + createMountPoints = true; + exports = '' + /export/nix-root 10.141.0.0/24(ro) + ''; + }; + + fileSystems = { + "/export/nix-root" = { + device = "/nix/store"; + options = [ "bind" ]; + }; + }; }; } -- cgit v1.2.3