diff --git a/configurers/networkd.nix b/configurers/networkd.nix index b73bc1c..b0bf997 100644 --- a/configurers/networkd.nix +++ b/configurers/networkd.nix @@ -2,4 +2,48 @@ * 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/. - */ \ No newline at end of file + */ +{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 \ No newline at end of file diff --git a/configurers/networkmanager.nix b/configurers/networkmanager.nix deleted file mode 100644 index b73bc1c..0000000 --- a/configurers/networkmanager.nix +++ /dev/null @@ -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/. - */ \ No newline at end of file diff --git a/configurers/static.nix b/configurers/static.nix index 1bd584f..a54ca27 100644 --- a/configurers/static.nix +++ b/configurers/static.nix @@ -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 \ No newline at end of file diff --git a/lib.nix b/lib.nix index 114ed3a..ba9f67a 100644 --- a/lib.nix +++ b/lib.nix @@ -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 = { diff --git a/wire.nix b/wire.nix index 1b1c5dc..7b9cfa7 100644 --- a/wire.nix +++ b/wire.nix @@ -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`