infrastructure/modules/nixos/dgn-network.nix
Tom Hubrecht 08d7dc46b3
All checks were successful
Build all the nodes / ap01 (pull_request) Successful in 1m11s
Build all the nodes / storage01 (pull_request) Successful in 2m24s
Build all the nodes / web02 (pull_request) Successful in 2m4s
Build all the nodes / compute01 (pull_request) Successful in 1h40m50s
Build all the nodes / bridge01 (pull_request) Successful in 1m57s
Build all the nodes / vault01 (pull_request) Successful in 1m51s
Build all the nodes / web03 (pull_request) Successful in 1m40s
Check meta / check_meta (pull_request) Successful in 20s
Build all the nodes / geo02 (pull_request) Successful in 1m59s
Check meta / check_dns (pull_request) Successful in 20s
Build all the nodes / geo01 (pull_request) Successful in 2m9s
Check workflows / check_workflows (pull_request) Successful in 28s
Build all the nodes / rescue01 (pull_request) Successful in 2m23s
Run pre-commit on all files / pre-commit (pull_request) Successful in 38s
Build all the nodes / web01 (pull_request) Successful in 2m36s
Run pre-commit on all files / pre-commit (push) Successful in 52s
fix(modules/dgn-network): Make it work on web02
This is the only node still on 24.05 as the cas server is f*cked
2024-12-15 23:33:14 +01:00

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;
};
}