nixos/iface-templates.nix
2025-04-19 05:07:57 +00:00

58 lines
1.4 KiB
Nix

{lib,...}:
let build = iface: mac: rest: lib.recursiveUpdate rest {
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;
};
}; in
{
bridge = br: ip: gateway: iface: mac: build iface mac {
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;
};
}