Cleanup the configurer by moving helpers into lib

release
Matthew Salerno 1 year ago
parent f45752f5d7
commit 18b08d06ec

@ -10,14 +10,8 @@ let
# these aren't really important, I just wanted to reverse the argument order
forEachAttr' = flip mapAttrs';
forEachAttrToList = flip mapAttrsToList;
keyProvidersInit = map (x: x inputs intermediateConfig peerName) keyProviders;
getPeerPubKey = otherPeerName: findFirst (x: x != null) (throw "Wirenix: Could not find public key for " + otherPeerName)
(map (provider: provider.getPeerPubKey otherPeerName) keyProvidersInit);
getPrivKeyFile = findFirst (x: x != null) (throw "Wirenix: Could not find private key file for " + peerName)
(map (provider: provider.getPrivKeyFile) keyProvidersInit);
getSubnetPSKFile = subnetName: findFirst (x: x != null) (null)
(map (provider: provider.getSubnetPSKFile subnetName) keyProvidersInit);
in
with getKeyProviderFuncs keyProviders inputs intermediateConfig peerName;
{
networking.wireguard = {
interfaces = forEachAttr' thisPeer.subnetConnections (subnetName: subnetConnection: { name = "wn-${subnetName}";

@ -2,6 +2,17 @@ with builtins;
/**
ACL independent functions that can be used in parsers.
*/
let
# stubbornly not passing lib and reimplementing everything since 2023
findFirst = pred: default: list:
if length list == 0
then default
else
if pred (head list)
then head list
else findFirst pred default (tail list);
in
rec {
/** Builtin Parsers */
defaultParsers = {
@ -98,5 +109,18 @@ rec {
name: value: (lib.attrsets.attrByPath ["config" "modules" "wirenix" "peerName"] null value) == peerName
) nixosConfigurations));
getKeyProviderFuncs = keyProvidersUninitialized: inputs: intermediateConfig: peerName:
let
keyProviders = map (x: x inputs intermediateConfig peerName) keyProvidersUninitialized;
in
{
getPeerPubKey = otherPeerName: findFirst (x: x != null) (throw ("Wirenix: Could not find public key for " + otherPeerName))
(map (provider: provider.getPeerPubKey otherPeerName) keyProviders);
getPrivKeyFile = findFirst (x: x != null) (throw ("Wirenix: Could not find private key file for " + peerName))
(map (provider: provider.getPrivKeyFile) keyProviders);
getSubnetPSKFile = subnetName: findFirst (x: x != null) (null)
(map (provider: provider.getSubnetPSKFile subnetName) keyProviders);
};
mergeIf = attr: key: if builtins.hasAttr key attr then {"${key}" = attr."${key}";} else {};
}
Loading…
Cancel
Save