nixos-module/container/upstream: style

This commit is contained in:
Astro 2021-04-08 01:48:40 +02:00
parent 9615317bf6
commit 8bdeedea9a
1 changed files with 5 additions and 1 deletions

View File

@ -4,12 +4,15 @@ 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;
enabled = (firstUpstreamInterface != null);
in
{
systemd.network.networks = {
@ -32,6 +35,7 @@ in
networkConfig.IPv6AcceptRA = true;
dhcpV6Config.PrefixDelegationHint = "::/56";
# Traffic Shaping
extraConfig = ''
[CAKE]
Parent = root
@ -41,7 +45,7 @@ in
'';
}) upstreamInterfaces;
networking.nat = lib.optionalAttrs (firstUpstreamInterface != null) {
networking.nat = lib.optionalAttrs enabled {
enable = true;
internalInterfaces = [ "core" ];
externalInterface = firstUpstreamInterface;