{ config, flake, ... }: let inherit (flake.config.services.instances) wireGuard web; inherit (flake.config.machines.devices) mars; service = wireGuard; in { networking = { firewall = { allowedUDPPorts = [ 53 service.ports.port0 ]; interfaces.wg0.allowedTCPPorts = [ 80 443 8080 ]; }; nat = { enable = true; enableIPv6 = true; externalInterface = "eth0"; internalInterfaces = [ "wg0" ]; }; wireguard.interfaces = { wg0 = { ips = [ "${web.wireguard.interface0}/24" ]; listenPort = service.ports.port0; privateKeyFile = config.sops.secrets."${service.name}-private".path; peers = [ { publicKey = "9zfRPxkxTLHM9tABC8lIaDMrzdjcF2l1mtG82uqGKUQ="; allowedIPs = [ "${mars.wireguard.ip0}/32" ]; } ]; }; }; }; sops = let sopsPath = secret: { path = "${service.sops.path0}/${service.name}-${secret}-pass"; owner = "root"; mode = "600"; }; in { secrets = builtins.listToAttrs ( map (secret: { name = "${service.name}-${secret}"; value = sopsPath secret; }) [ "private" "public" ] ); }; boot.kernel.sysctl = { "net.ipv4.ip_forward" = 1; }; }