2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
meta,
|
|
|
|
name,
|
2024-04-18 15:53:20 +02:00
|
|
|
nodeMeta,
|
2024-02-02 10:51:31 +01:00
|
|
|
...
|
|
|
|
}:
|
2023-07-20 12:32:31 +02:00
|
|
|
|
|
|
|
let
|
2024-02-23 10:50:50 +01:00
|
|
|
inherit (lib) mapAttrs' mkEnableOption mkIf;
|
2023-07-20 12:32:31 +02:00
|
|
|
|
2024-02-20 17:47:34 +01:00
|
|
|
net' = meta.network.${name};
|
2023-07-20 12:32:31 +02:00
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
mkAddress = { address, prefixLength, ... }: "${address}/${builtins.toString prefixLength}";
|
2023-12-04 12:36:31 +01:00
|
|
|
mkRoute = gateway: {
|
|
|
|
routeConfig = {
|
|
|
|
Gateway = gateway;
|
|
|
|
GatewayOnLink = true;
|
|
|
|
};
|
|
|
|
};
|
2023-07-20 12:32:31 +02:00
|
|
|
|
|
|
|
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;
|
2023-07-20 12:32:31 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg = config.dgn-network;
|
2024-02-02 10:51:31 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.dgn-network.enable = mkEnableOption "automatic network configuration based on metadata" // {
|
|
|
|
default = true;
|
|
|
|
};
|
2023-07-20 12:32:31 +02:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
networking = {
|
2024-02-20 17:47:34 +01:00
|
|
|
inherit (net') hostId;
|
2023-07-20 12:32:31 +02:00
|
|
|
|
|
|
|
hostName = name;
|
2024-04-18 15:53:20 +02:00
|
|
|
domain = "${nodeMeta.site}.infra.dgnum.eu";
|
2023-07-20 12:32:31 +02:00
|
|
|
useNetworkd = true;
|
2023-11-13 14:21:52 +01:00
|
|
|
|
|
|
|
firewall.logRefusedConnections = false;
|
2023-07-20 12:32:31 +02:00
|
|
|
};
|
|
|
|
|
2024-02-20 17:47:34 +01:00
|
|
|
systemd.network.networks = mapAttrs' mkInterface net'.interfaces;
|
2023-07-20 12:32:31 +02:00
|
|
|
};
|
|
|
|
}
|