forked from zentralwerk/network
33 lines
849 B
Nix
33 lines
849 B
Nix
{ hostName, config, lib, ... }:
|
|
|
|
let
|
|
upstreamInterfaces =
|
|
lib.filterAttrs (_: { upstream, ... }: upstream != null)
|
|
config.site.hosts.${hostName}.interfaces;
|
|
firstUpstreamInterface =
|
|
if builtins.length (builtins.attrNames upstreamInterfaces) > 0
|
|
then builtins.head (
|
|
builtins.attrNames upstreamInterfaces
|
|
)
|
|
else null;
|
|
in
|
|
{
|
|
systemd.network.networks = builtins.mapAttrs (_: { upstream, ... }: {
|
|
DHCP = "yes";
|
|
|
|
extraConfig = ''
|
|
[CAKE]
|
|
Parent = root
|
|
# DOCSIS overhead
|
|
OverheadBytes = 18
|
|
Bandwidth = ${toString upstream.upBandwidth}K
|
|
'';
|
|
}) upstreamInterfaces;
|
|
|
|
networking.nat = lib.optionalAttrs (firstUpstreamInterface != null) {
|
|
enable = true;
|
|
externalInterface = firstUpstreamInterface;
|
|
forwardPorts = config.site.hosts.${hostName}.forwardedPorts;
|
|
};
|
|
}
|