add networkd

release
Matthew Salerno 1 year ago
parent 630ce0585b
commit 6c047213c0

@ -3,3 +3,47 @@
* 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/.
*/
{lib, ...}@inputs: keyProviders: intermediateConfig: peerName:
with lib.trivial;
with lib.attrsets;
with lib.lists;
with lib;
with builtins;
with import ../lib.nix;
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
with getKeyProviderFuncs keyProviders inputs intermediateConfig peerName;
{
systemd.network = {
netdevs = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "50-wn-${subnetName}" {
netdevConfig = {
Kind = "wireguard";
Name = "wn-${subnetName}";
};
wireguardConfig = {
PrivateKeyFile = getPrivKeyFile;
ListenPort = subnetConnection.listenPort;
};
wireguardPeers = forEachAttrToList subnetConnection.peerConnections (otherPeerName: peerConnection: {
wireguardPeerConfig = {
Endpoint = "${peerConnection.endpoint.ip}:${builtins.toString peerConnection.endpoint.port}";
PublicKey = getPeerPubKey otherPeerName;
AllowedIPs = peerConnection.ipAddresses;
PresharedKeyFile = getSubnetPSKFile subnetName;
};
}
// (if peerConnection.endpoint ? persistentKeepalive then {PersistentKeepalive = peerConnection.endpoint.persistentKeepalive;} else {})
// (warnIf (peerConnection.endpoint ? dynamicEndpointRefreshSeconds) "dynamicEndpointRefreshSeconds not supported for networkd" {})
// (warnIf (peerConnection.endpoint ? dynamicEndpointRefreshRestartSeconds) "dynamicEndpointRefreshRestartSeconds not supported for networkd" {})
);
});
networks = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "${subnetName}" {
matchConfig.Name = "wn-${subnetName}";
address = subnetConnection.ipAddresses;
});
};
} // getProviderConfig

@ -1,5 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/

@ -19,8 +19,8 @@ in
with getKeyProviderFuncs keyProviders inputs intermediateConfig peerName;
{
networking.wireguard = {
interfaces = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: { name = "wn-${subnetName}";
value = {
interfaces = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: nameValuePair "wn-${subnetName}"
{
ips = subnetConnection.ipAddresses;
listenPort = subnetConnection.listenPort;
privateKeyFile = getPrivKeyFile;
@ -36,7 +36,7 @@ with getKeyProviderFuncs keyProviders inputs intermediateConfig peerName;
// (mergeIf peerConnection.endpoint "dynamicEndpointRefreshSeconds")
// (mergeIf peerConnection.endpoint "dynamicEndpointRefreshRestartSeconds")
);
};}
}
);
};
} // getProviderConfig

@ -27,7 +27,6 @@ rec {
defaultConfigurers = {
static = import ./configurers/static.nix;
networkd = import ./configurers/networkd.nix;
network-manager = import ./configurers/networkmanager.nix;
};
/** Builtin key providers */
defaultKeyProviders = {

@ -47,14 +47,14 @@ in
type = types.str;
description = mdDoc ''
Configurer to use. Builtin values can be
"static" "networkd" or "network-manager"
Or you can put your own configurer here.
"static" or "networkd". Or, you can put
your own configurer that you registered in
`additionalConfigurers` here.
'';
};
keyProviders = mkOption {
default = ["acl"];
type = with types; listOf str;
defaultText = literalExpression "[ "acl" ]";
description = mdDoc ''
List of key providers. Key providers will be queried in order.
Builtin providers are `wirenix.lib.defaultKeyProviders.acl`

Loading…
Cancel
Save