2024-12-07 16:23:58 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
meta,
|
|
|
|
name,
|
|
|
|
nodeMeta,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-12-07 16:24:14 +01:00
|
|
|
inherit (lib)
|
|
|
|
mapAttrs'
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkForce
|
|
|
|
;
|
2024-12-07 16:23:58 +01:00
|
|
|
|
|
|
|
net' = meta.network.${name};
|
|
|
|
|
|
|
|
mkAddress = { address, prefixLength, ... }: "${address}/${builtins.toString prefixLength}";
|
|
|
|
mkRoute = gateway: {
|
|
|
|
routeConfig = {
|
|
|
|
Gateway = gateway;
|
|
|
|
GatewayOnLink = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkInterface = interface: net: {
|
|
|
|
name = "10-${interface}";
|
|
|
|
value = {
|
|
|
|
name = interface;
|
|
|
|
address = builtins.map mkAddress (net.ipv4 ++ net.ipv6);
|
|
|
|
routes = builtins.map mkRoute net.gateways;
|
|
|
|
|
|
|
|
inherit (net) DHCP dns;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg = config.lab-network;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.lab-network.enable = mkEnableOption "automatic network configuration based on metadata" // {
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkForce {
|
|
|
|
networking = {
|
|
|
|
inherit (net') hostId;
|
|
|
|
|
|
|
|
hostName = name;
|
|
|
|
domain = "${nodeMeta.site}.infra.lab.dgnum.eu";
|
|
|
|
useNetworkd = true;
|
|
|
|
|
|
|
|
firewall.logRefusedConnections = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.network.networks = mapAttrs' mkInterface net'.interfaces;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|