···
let cfg = config.wireguard; in
8
-
enable = lib.mkEnableOption "wireguard";
8
+
enable = mkEnableOption "wireguard";
default = cfg.hosts.${config.networking.hostName}.server;
···
26
+
endpoint = mkOption {
27
+
type = with types; nullOr str;
29
+
# should not be null when server = true
31
+
persistentKeepalive = mkOption {
32
+
type = with types; nullOr int;
···
51
-
ips = [ "${cfg.hosts.${config.networking.hostName}.ip}/24" ];
59
+
interfaces.wg0 = let hostName = config.networking.hostName; in {
60
+
ips = [ "${cfg.hosts."${hostName}".ip}/24" ];
53
-
privateKeyFile = "${config.custom.secretsDir}/wireguard-key-${config.networking.hostName}";
54
-
peers = mkIf (!cfg.server) [
56
-
allowedIPs = [ "10.0.0.0/24" ];
57
-
publicKey = "${cfg.hosts.vps.publicKey}";
58
-
endpoint = "${config.hosting.serverIpv4}:51820";
59
-
persistentKeepalive = mkIf (config.networking.hostName == "rasp-pi") 25;
62
+
privateKeyFile = "${config.custom.secretsDir}/wireguard-key-${hostName}";
65
+
serverPeers = attrsets.mapAttrsToList
67
+
if values.server then
69
+
allowedIPs = [ "10.0.0.0/24" ];
70
+
publicKey = values.publicKey;
71
+
endpoint = "${values.endpoint}:51820";
72
+
persistentKeepalive = values.persistentKeepalive;
76
+
# remove empty elements
77
+
cleanedServerPeers = lists.remove { } serverPeers;
78
+
in mkIf (!cfg.server) cleanedServerPeers;