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 = upstreamInterfaces =
lib.filterAttrs (_: { upstream, ... }: upstream != null) lib.filterAttrs (_: { upstream, ... }: upstream != null)
config.site.hosts.${hostName}.interfaces; config.site.hosts.${hostName}.interfaces;
firstUpstreamInterface = firstUpstreamInterface =
if builtins.length (builtins.attrNames upstreamInterfaces) > 0 if builtins.length (builtins.attrNames upstreamInterfaces) > 0
then builtins.head ( then builtins.head (
builtins.attrNames upstreamInterfaces builtins.attrNames upstreamInterfaces
) )
else null; else null;
enabled = (firstUpstreamInterface != null);
in in
{ {
systemd.network.networks = { systemd.network.networks = {
@ -32,6 +35,7 @@ in
networkConfig.IPv6AcceptRA = true; networkConfig.IPv6AcceptRA = true;
dhcpV6Config.PrefixDelegationHint = "::/56"; dhcpV6Config.PrefixDelegationHint = "::/56";
# Traffic Shaping
extraConfig = '' extraConfig = ''
[CAKE] [CAKE]
Parent = root Parent = root
@ -41,7 +45,7 @@ in
''; '';
}) upstreamInterfaces; }) upstreamInterfaces;
networking.nat = lib.optionalAttrs (firstUpstreamInterface != null) { networking.nat = lib.optionalAttrs enabled {
enable = true; enable = true;
internalInterfaces = [ "core" ]; internalInterfaces = [ "core" ];
externalInterface = firstUpstreamInterface; externalInterface = firstUpstreamInterface;