{ 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; internalInterfaces = [ "core" ]; externalInterface = firstUpstreamInterface; forwardPorts = config.site.hosts.${hostName}.forwardedPorts; }; }