factor out evaluating options

Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
Kiara Grouwstra 2025-11-03 16:16:11 +01:00
parent 0cf646abfa
commit 60ddfaa0ad
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
2 changed files with 22 additions and 24 deletions

View file

@ -6,6 +6,7 @@
}: }:
let let
inherit (pkgs) system; inherit (pkgs) system;
inherit (pkgs.callPackage ../../utils.nix { }) evalOption;
backendPort = builtins.toString 8080; backendPort = builtins.toString 8080;
tfBackend = fragment: { tfBackend = fragment: {
address = "http://localhost:${backendPort}/state/${fragment}"; address = "http://localhost:${backendPort}/state/${fragment}";
@ -17,30 +18,14 @@ let
tf-netbox-store-ips tf-netbox-store-ips
tf-netbox-get-ip tf-netbox-get-ip
; ;
netbox-store-ips = netbox-store-ips = evalOption "tf-netbox-store-ips" tf-netbox-store-ips {
(lib.evalModules { httpBackend = tfBackend "proxmox-test/store-ips";
modules = [ startAddress = "192.168.10.236/24";
{ endAddress = "192.168.10.240/24";
options = { inherit tf-netbox-store-ips; }; };
config.tf-netbox-store-ips = { netbox-get-ip = evalOption "tf-netbox-get-ip" tf-netbox-get-ip {
httpBackend = tfBackend "proxmox-test/store-ips"; httpBackend = tfBackend "proxmox-test/get-ip";
startAddress = "192.168.10.236/24"; };
endAddress = "192.168.10.240/24";
};
}
];
}).config.tf-netbox-store-ips;
netbox-get-ip =
(lib.evalModules {
modules = [
{
options = { inherit tf-netbox-get-ip; };
config.tf-netbox-get-ip = {
httpBackend = tfBackend "proxmox-test/get-ip";
};
}
];
}).config.tf-netbox-get-ip;
netboxUser = "netbox"; netboxUser = "netbox";
netboxPassword = "netbox"; netboxPassword = "netbox";
changePassword = pkgs.writeText "change-password.py" '' changePassword = pkgs.writeText "change-password.py" ''

View file

@ -18,6 +18,19 @@ rec {
]; ];
}).config; }).config;
evalOption =
name: opts: conf:
(lib.evalModules {
modules = [
{
options = {
"${name}" = opts;
};
config."${name}" = conf;
}
];
}).config."${name}";
toBash = toBash =
v: v:
lib.replaceStrings [ "\"" ] [ "\\\"" ] ( lib.replaceStrings [ "\"" ] [ "\\\"" ] (