{ lib, config, pkgs, ... }: with lib; let psCfg = config.pub-solar; cfg = config.pub-solar.wireguard.pub-solar; in { options.pub-solar.wireguard.pub-solar = { ownIPs = mkOption { description = "Internal ips in wireguard used for cluster control-plane communication."; type = types.listOf types.str; default = []; }; privateKeyFile = mkOption { description = "Location of private key file"; type = types.path; }; }; config = mkIf (length cfg.ownIPs != 0){ networking.firewall.allowedUDPPorts = [51821]; systemd.network.wait-online.ignoredInterfaces = [ "wg-pub-solar" ]; systemd.services.wireguard-wg-pub-solar = { after = [ "network.target" "network-online.target" "nss-lookup.target" ]; serviceConfig = { Type = mkForce "simple"; Restart = "on-failure"; RestartSec = "30"; }; environment = { WG_ENDPOINT_RESOLUTION_RETRIES = "infinity"; }; }; networking.wireguard.interfaces = { wg-pub-solar = { listenPort = 51821; mtu = 1300; ips = cfg.ownIPs; privateKeyFile = cfg.privateKeyFile; peers = [ { endpoint = "flora-6.pub.solar:51820"; publicKey = "jtSR5G2P/nm9s8WrVc26Xc/SQLupRxyXE+5eIeqlsTU="; allowedIPs = [ "10.7.6.2/32" "fd00:fae:fae:fae:fae:2::/96" ]; persistentKeepalive = 15; dynamicEndpointRefreshSeconds = 30; } { endpoint = "nachtigall.pub.solar:51820"; publicKey = "qzNywKY9RvqTnDO8eLik75/SHveaSk9OObilDzv+xkk="; allowedIPs = [ "10.7.6.1/32" "fd00:fae:fae:fae:fae:1::/96" ]; persistentKeepalive = 15; dynamicEndpointRefreshSeconds = 30; } ]; }; }; }; }