{ lib, pkgs, config, ... }: let cfg = config.pub-solar.wireguard.ehex; in { options.pub-solar.wireguard.ehex = { ownIPs = lib.mkOption { description = "Internal ips in wireguard used for cluster control-plane communication."; type = lib.types.listOf lib.types.str; default = []; }; privateKeyFile = lib.mkOption { description = "Location of private key file"; type = lib.types.path; }; }; config = lib.mkIf (lib.length cfg.ownIPs != 0) { networking.firewall.allowedUDPPorts = [51822]; systemd.network.wait-online.ignoredInterfaces = ["wg-ehex"]; systemd.services.wireguard-wg-ehex = import ./service-override.nix lib; networking.wireguard.interfaces = { wg-ehex = { listenPort = 51822; mtu = 1300; ips = cfg.ownIPs; privateKeyFile = cfg.privateKeyFile; postSetup = '' ${pkgs.systemd}/bin/resolvectl dns wg-ehex 10.0.66.10 10.0.66.12 ${pkgs.systemd}/bin/resolvectl domain wg-ehex ehex.cloud ''; peers = [ { endpoint = "vpn-gateway.ehex.de:4242"; publicKey = "Fsg4KEyDEvQEt/1cVWU9xa/k9x/3UhONDj61aXZ7tys="; presharedKey = "tQy7B5R3wOgWwIKFDcEr4WZIqCrwG+9UgPRIQx/5xso="; allowedIPs = ["10.42.0.0/22" "10.0.66.0/24"]; persistentKeepalive = 15; dynamicEndpointRefreshSeconds = 30; } ]; }; }; }; }