mirror of
https://git.mediani.de/mirrors_public/oddlama_nixos-extra-modules.git
synced 2025-10-10 22:10:38 +02:00
perf: allow caching wireguard network information to significantly speed up evaluation
This commit is contained in:
parent
ba53e1a0be
commit
0de9c0751b
3 changed files with 27 additions and 8 deletions
|
@ -16,6 +16,7 @@ inputs: final: prev: let
|
|||
nameValuePair
|
||||
partition
|
||||
removeSuffix
|
||||
warn
|
||||
;
|
||||
|
||||
inherit
|
||||
|
@ -32,8 +33,8 @@ inputs: final: prev: let
|
|||
in {
|
||||
lib =
|
||||
prev.lib
|
||||
// {
|
||||
wireguard = userInputs: wgName: let
|
||||
// rec {
|
||||
wireguard.evaluateNetwork = userInputs: wgName: let
|
||||
inherit (userInputs.self) nodes;
|
||||
# Returns the given node's wireguard configuration of this network
|
||||
wgCfgOf = node: nodes.${node}.config.wireguard.${wgName};
|
||||
|
@ -220,5 +221,24 @@ in {
|
|||
wgQuickConfigScript
|
||||
;
|
||||
};
|
||||
|
||||
wireguard.createEvalCache = userInputs: wgNames:
|
||||
genAttrs wgNames (wireguard.evaluateNetwork userInputs);
|
||||
|
||||
wireguard.getNetwork = userInputs: wgName:
|
||||
userInputs.self.wireguardEvalCache.${wgName}
|
||||
or (
|
||||
warn ''
|
||||
The calculated information for the wireguard network "${wgName}" is not cached!
|
||||
This will siginificantly increase evaluation times. Please consider pre-evaluating
|
||||
this information by exposing it in your flake:
|
||||
|
||||
wireguardEvalCache.${wgName} = lib.wireguard.createEvalCache inputs [
|
||||
"${wgName}"
|
||||
# all other networks
|
||||
];
|
||||
|
||||
'' (wireguard.evaluateNetwork userInputs wgName)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue