{ 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 (_: _: { DHCP = "yes"; }) upstreamInterfaces; networking.nat = lib.optionalAttrs (firstUpstreamInterface != null) { enable = true; externalInterface = firstUpstreamInterface; forwardPorts = config.site.hosts.${hostName}.forwardedPorts; }; }