You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.5 KiB
Nix
39 lines
1.5 KiB
Nix
{lib, ...}: intermediateConfig: peerName:
|
|
with lib.trivial;
|
|
with lib.attrsets;
|
|
with lib.lists;
|
|
with lib;
|
|
let
|
|
thisPeer = intermediateConfig.peers."${peerName}";
|
|
# these aren't really important, I just wanted to reverse the argument order
|
|
forEachAttr' = flip mapAttrs';
|
|
forEachAttrToList = flip mapAttrsToList;
|
|
in
|
|
{
|
|
networking.wireguard = {
|
|
interfaces = forEachAttr' thisPeer.subnetConnections (name: subnetConnection: { name = "wg-${name}";
|
|
value = {
|
|
ips = subnetConnection.ipAddresses;
|
|
listenPort = subnetConnection.listenPort;
|
|
privateKeyFile = thisPeer.privateKeyFile;
|
|
peers = forEachAttrToList subnetConnection.peerConnections (peerName: peerConnection: mkMerge [
|
|
{
|
|
name = peerName;
|
|
publicKey = peerConnection.peer.publicKey;
|
|
allowedIPs = peerConnection.ipAddresses;
|
|
endpoint = "${peerConnection.endpoint.ip}:${peerConnection.endpoint.port}";
|
|
}
|
|
mkIf (peerConnection.endpoint ? persistentKeepalive) {
|
|
persistentKeepalive = peerConnection.endpoint.persistentKeepalive;
|
|
}
|
|
mkIf (peerConnection.endpoint ? dynamicEndpointRefreshSeconds) {
|
|
dynamicEndpointRefreshSeconds = peerConnection.endpoint.dynamicEndpointRefreshSeconds;
|
|
}
|
|
mkIf (peerConnection.endpoint ? dynamicEndpointRefreshRestartSeconds) {
|
|
dynamicEndpointRefreshRestartSeconds = peerConnection.endpoint.dynamicEndpointRefreshRestartSeconds;
|
|
}
|
|
]);
|
|
};}
|
|
);
|
|
};
|
|
} |