From 210d5b135ceb5ac24a6c91441f8c5edd4d1cf5d2 Mon Sep 17 00:00:00 2001 From: James Andariese Date: Sat, 19 Apr 2025 05:07:57 +0000 Subject: [PATCH] wip --- hosts/yveltal.nix | 15 +++++------ iface-templates.nix | 57 +++++++++++++++++++++++++++++++----------- modules/luks-zero.key | Bin 0 -> 32 bytes modules/luks.nix | 6 ++++- 4 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 modules/luks-zero.key diff --git a/hosts/yveltal.nix b/hosts/yveltal.nix index c35c595..36f5e86 100644 --- a/hosts/yveltal.nix +++ b/hosts/yveltal.nix @@ -4,18 +4,19 @@ { config, pkgs, lib, inputs, ... }: -let iface = import ../iface-templates.nix {inherit lib;}; -in { +{ imports = [ # Include the results of the hardware scan. ../types/server.nix ]; config = lib.mkMerge [ - (iface.bridge "lan0" "172.16.1.251/12" "172.16.1.1" "phy0" "50:9a:4c:49:cc:1b") - (iface.dhcp "phy1" "98:b7:85:01:36:ec") - (iface.dhcp "phy2" "98:b7:85:01:36:ed") - (iface.dhcp "phy3" "98:b7:85:01:36:ee") - (iface.dhcp "phy4" "98:b7:85:01:36:ef") + {networking.interfaces.enp0s31f6.useDHCP = true;} + #{networking.interfaces.enp0s31f6.ipv4.addresses = [ address = "172.16.1.251"; prefixLength = 12; }]} + #(iface.bridge "lan0" "172.16.1.251/12" "172.16.1.1" "phy0" "50:9a:4c:49:cc:1b") + #(iface.dhcp "phy1" "98:b7:85:01:36:ec") + #(iface.dhcp "phy2" "98:b7:85:01:36:ed") + #(iface.dhcp "phy3" "98:b7:85:01:36:ee") + #(iface.dhcp "phy4" "98:b7:85:01:36:ef") ]; } diff --git a/iface-templates.nix b/iface-templates.nix index 3ee6097..cb2543f 100644 --- a/iface-templates.nix +++ b/iface-templates.nix @@ -1,30 +1,57 @@ {lib,...}: let build = iface: mac: rest: lib.recursiveUpdate rest { - systemd.network.enable = true; - systemd.network.links."${iface}" = { - linkConfig.Name = iface; - matchConfig.PermanentMACAddress = mac; + networking.usePredictableInterfaceNames = false; + boot.initrd.systemd.enable = true; + + boot.initrd.services.udev.rules = '' + SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", \ + ADDR{address}=="${mac}", KERNEL="eth*", NAME="${iface}" + ''; + boot.initrd.systemd.network = { + enable = true; + links."${iface}" = { + linkConfig.Name = iface; + matchConfig.PermanentMACAddress = mac; + }; + wait-online.enable = false; + }; + systemd.network = { + enable = true; + links."${iface}" = { + linkConfig.Name = iface; + matchConfig.PermanentMACAddress = mac; + }; + networks."${iface}".enable = true; + wait-online.anyInterface = true; }; - systemd.network.networks."${iface}".enable = true; }; in { bridge = br: ip: gateway: iface: mac: build iface mac { - systemd.network.networks."${iface}".bridge = [ br ]; - systemd.network.networks."${br}" = { - address = [ ip ]; - gateway = [ gateway ]; - }; - systemd.network.netdevs."${br}" = { - netdevConfig = { - Name = br; - Kind = "bridge"; + systemd.network = { + networks = { + "${iface}".bridge = [ br ]; + + "${br}" = { + address = [ ip ]; + gateway = [ gateway ]; + }; + }; + netdevs = { + "${br}" = { + netdevConfig = { + Name = br; + Kind = "bridge"; + }; + }; }; }; - }; + }; dhcp = iface: mac: build iface mac { systemd.network.networks."${iface}" = { + matchConfig.Name = iface; DHCP = "yes"; }; + networking.interfaces."${iface}".useDHCP = true; }; } diff --git a/modules/luks-zero.key b/modules/luks-zero.key new file mode 100644 index 0000000000000000000000000000000000000000..4e4e4935707a596987ec1cc32e3d0d587dbe4f04 GIT binary patch literal 32 KcmZQzzz+ZbAOHaX literal 0 HcmV?d00001 diff --git a/modules/luks.nix b/modules/luks.nix index 1380906..28587f6 100644 --- a/modules/luks.nix +++ b/modules/luks.nix @@ -7,9 +7,13 @@ device = "/dev/disk/by-partlabel/${config.networking.hostName}-luks0"; allowDiscards = true; keyFileSize = 32; - keyFile = "/dev/zero"; + keyFile = "/dev/zero"; + #keyFile = "/etc/luks-zero.key"; }; }; + #boot.initrd.systemd.contents = { + # "/etc/luks-zero.key".source = ./luks-zero.key; + #}; fileSystems."/" = { device = "/dev/disk/by-label/${config.networking.hostName}-root"; fsType = "ext4";