|
|
@ -3,7 +3,7 @@
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
{lib, ...}@inputs: keyProviders: intermediateConfig: peerName:
|
|
|
|
{lib, ...}@inputs: keyProviders: intermediateConfig: localPeerName:
|
|
|
|
with lib.trivial;
|
|
|
|
with lib.trivial;
|
|
|
|
with lib.attrsets;
|
|
|
|
with lib.attrsets;
|
|
|
|
with lib.lists;
|
|
|
|
with lib.lists;
|
|
|
@ -11,31 +11,32 @@ with lib;
|
|
|
|
with builtins;
|
|
|
|
with builtins;
|
|
|
|
with import ../lib.nix;
|
|
|
|
with import ../lib.nix;
|
|
|
|
let
|
|
|
|
let
|
|
|
|
thisPeer = intermediateConfig.peers."${peerName}";
|
|
|
|
thisPeer = intermediateConfig.peers."${localPeerName}";
|
|
|
|
# these aren't really important, I just wanted to reverse the argument order
|
|
|
|
# these aren't really important, I just wanted to reverse the argument order
|
|
|
|
forEachAttr' = flip mapAttrs';
|
|
|
|
forEachAttr' = flip mapAttrs';
|
|
|
|
forEachAttrToList = flip mapAttrsToList;
|
|
|
|
forEachAttrToList = flip mapAttrsToList;
|
|
|
|
|
|
|
|
shortName = fqdn: head (strings.splitString "." fqdn);
|
|
|
|
in
|
|
|
|
in
|
|
|
|
with getKeyProviderFuncs keyProviders inputs intermediateConfig peerName;
|
|
|
|
with getKeyProviderFuncs keyProviders inputs intermediateConfig localPeerName;
|
|
|
|
{
|
|
|
|
{
|
|
|
|
networking.extraHosts = concatStringsSep "\n" (concatLists ( concatLists (forEachAttrToList thisPeer.subnetConnections (subnetName: subnetConnection:
|
|
|
|
networking.extraHosts = concatStringsSep "\n" (concatLists ( concatLists (forEachAttrToList thisPeer.subnetConnections (subnetName: subnetConnection:
|
|
|
|
forEachAttrToList subnetConnection.peerConnections (otherPeerName: peerConnection: forEach peerConnection.ipAddresses (ip: "${strings.removeSuffix "/64" ip} ${otherPeerName}.${subnetName}"))
|
|
|
|
forEachAttrToList subnetConnection.peerConnections (remotePeerName: peerConnection: forEach peerConnection.ipAddresses (ip: "${strings.removeSuffix "/64" ip} ${remotePeerName}.${subnetName}"))
|
|
|
|
))));
|
|
|
|
))));
|
|
|
|
systemd.network = {
|
|
|
|
systemd.network = {
|
|
|
|
netdevs = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "50-wn-${subnetName}" {
|
|
|
|
netdevs = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "50-${shortName subnetName}" {
|
|
|
|
netdevConfig = {
|
|
|
|
netdevConfig = {
|
|
|
|
Kind = "wireguard";
|
|
|
|
Kind = "wireguard";
|
|
|
|
Name = "wn-${subnetName}";
|
|
|
|
Name = "${shortName subnetName}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
wireguardConfig = {
|
|
|
|
wireguardConfig = {
|
|
|
|
PrivateKeyFile = getPrivKeyFile;
|
|
|
|
PrivateKeyFile = getPrivKeyFile;
|
|
|
|
ListenPort = subnetConnection.listenPort;
|
|
|
|
ListenPort = subnetConnection.listenPort;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
wireguardPeers = forEachAttrToList subnetConnection.peerConnections (otherPeerName: peerConnection: {
|
|
|
|
wireguardPeers = forEachAttrToList subnetConnection.peerConnections (remotePeerName: peerConnection: {
|
|
|
|
wireguardPeerConfig = {
|
|
|
|
wireguardPeerConfig = {
|
|
|
|
Endpoint = "${peerConnection.endpoint.ip}:${builtins.toString peerConnection.endpoint.port}";
|
|
|
|
Endpoint = "${peerConnection.endpoint.ip}:${builtins.toString peerConnection.endpoint.port}";
|
|
|
|
PublicKey = getPeerPubKey otherPeerName;
|
|
|
|
PublicKey = getPeerPubKey remotePeerName;
|
|
|
|
AllowedIPs = peerConnection.ipAddresses;
|
|
|
|
AllowedIPs = map (ip: cidr2ip ip + "/128") peerConnection.ipAddresses;
|
|
|
|
PresharedKeyFile = getSubnetPSKFile subnetName;
|
|
|
|
PresharedKeyFile = getSubnetPSKFile subnetName;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -44,8 +45,8 @@ with getKeyProviderFuncs keyProviders inputs intermediateConfig peerName;
|
|
|
|
// (warnIf (peerConnection.endpoint ? dynamicEndpointRefreshRestartSeconds) "dynamicEndpointRefreshRestartSeconds not supported for networkd" {})
|
|
|
|
// (warnIf (peerConnection.endpoint ? dynamicEndpointRefreshRestartSeconds) "dynamicEndpointRefreshRestartSeconds not supported for networkd" {})
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
networks = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "${subnetName}" {
|
|
|
|
networks = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "50-${shortName subnetName}" {
|
|
|
|
matchConfig.Name = "wn-${subnetName}";
|
|
|
|
matchConfig.Name = "${shortName subnetName}";
|
|
|
|
address = subnetConnection.ipAddresses;
|
|
|
|
address = subnetConnection.ipAddresses;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|