2022-08-03 23:53:45 +03:00
|
|
|
{ cluster, config, ... }:
|
|
|
|
let
|
|
|
|
inherit (config.networking) hostName;
|
|
|
|
|
2023-03-22 22:26:02 +02:00
|
|
|
link = cluster.config.hostLinks.${hostName}.mesh;
|
2022-08-03 23:53:45 +03:00
|
|
|
|
|
|
|
mkPeer = peerName: let
|
2023-03-22 22:26:02 +02:00
|
|
|
peerLink = cluster.config.hostLinks.${peerName}.mesh;
|
2022-08-03 23:53:45 +03:00
|
|
|
in {
|
|
|
|
publicKey = peerLink.extra.pubKey;
|
2022-08-04 01:27:21 +03:00
|
|
|
allowedIPs = [ "${peerLink.extra.meshIp}/32" ] ++ peerLink.extra.extraRoutes;
|
2022-08-03 23:53:45 +03:00
|
|
|
endpoint = peerLink.tuple;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
age.secrets.wireguard-key-core = {
|
|
|
|
file = link.extra.privKeyFile;
|
|
|
|
mode = "0400";
|
|
|
|
};
|
|
|
|
|
|
|
|
networking = {
|
|
|
|
firewall = {
|
2022-08-04 01:13:59 +03:00
|
|
|
trustedInterfaces = [ "wgmesh" ];
|
2022-08-03 23:53:45 +03:00
|
|
|
allowedUDPPorts = [ link.port ];
|
|
|
|
};
|
|
|
|
|
|
|
|
wireguard = {
|
|
|
|
enable = true;
|
|
|
|
interfaces.wgmesh = {
|
|
|
|
ips = [ "${link.extra.meshIp}/24" ];
|
|
|
|
listenPort = link.port;
|
|
|
|
privateKeyFile = config.age.secrets.wireguard-key-core.path;
|
2023-08-31 01:55:45 +03:00
|
|
|
peers = map mkPeer (cluster.config.services.wireguard.otherNodes.mesh hostName);
|
2022-08-03 23:53:45 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|