infrastructure/modules/dgn-network.nix

55 lines
1 KiB
Nix
Raw Permalink Normal View History

{
config,
lib,
meta,
name,
2024-04-18 15:53:20 +02:00
nodeMeta,
...
}:
let
2024-02-23 10:50:50 +01:00
inherit (lib) mapAttrs' mkEnableOption mkIf;
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;
2024-02-23 10:50:50 +01:00
inherit (net) DHCP dns;
};
};
cfg = config.dgn-network;
in
{
options.dgn-network.enable = mkEnableOption "automatic network configuration based on metadata" // {
default = true;
};
config = mkIf cfg.enable {
networking = {
inherit (net') hostId;
hostName = name;
2024-04-18 15:53:20 +02:00
domain = "${nodeMeta.site}.infra.dgnum.eu";
useNetworkd = true;
firewall.logRefusedConnections = false;
};
systemd.network.networks = mapAttrs' mkInterface net'.interfaces;
};
}