{ config, pkgs, lib, cfg, ... }: let prefix = "meshconfig"; # helper vars to prettify meshnetwork = config.${prefix}.network; currentHost = meshnetwork.hosts.${networking.hostName}; wireguardPort = currentHost.wg.port; in { opt.useIPv6 = lib.mkOption { type = lib.types.bool; description = "Whether to use IPv6. Defaults to true"; default = true; }; networking.wireguard.interfaces.wg0 = { ips = ["${meshnetwork.IPv4.wg_subnet}"]; listenPort = cfg.wireguardPort; privateKeyFile = "/var/lib/wireguard-keys/private"; mtu = 1420; }; services.wgautomesh = { enable = true; services.wgautomesh.settings = { interface = "wg0"; peers = if cfg.useIPv6 then meshnetwork.IPv6.peerlist else meshnetwork.IPv4.peerlist; upnp_forward_external_port = wireguardPort; }; }; }