forked from DGNum/infrastructure
66 lines
1.3 KiB
Nix
66 lines
1.3 KiB
Nix
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
#
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
{
|
|
config,
|
|
lib,
|
|
meta,
|
|
name,
|
|
nodeMeta,
|
|
...
|
|
}:
|
|
|
|
let
|
|
inherit (lib) mapAttrs' mkEnableOption mkIf;
|
|
|
|
net' = meta.network.${name};
|
|
|
|
mkAddress = { address, prefixLength, ... }: "${address}/${builtins.toString prefixLength}";
|
|
mkRoute =
|
|
Gateway:
|
|
if name == "web02" then
|
|
{
|
|
routeConfig = {
|
|
inherit Gateway;
|
|
GatewayOnLink = true;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
inherit 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.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;
|
|
domain = "${nodeMeta.site}.infra.dgnum.eu";
|
|
useNetworkd = true;
|
|
|
|
firewall.logRefusedConnections = false;
|
|
};
|
|
|
|
systemd.network.networks = mapAttrs' mkInterface net'.interfaces;
|
|
};
|
|
}
|