From 8d5463587e56bfa71e7535e0ca4ba66ddcbe43a0 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sun, 15 Sep 2024 15:09:54 +0200 Subject: [PATCH] Inventory: set {name,meta.name} automatically --- lib/inventory/build-inventory/default.nix | 6 +- lib/inventory/build-inventory/interface.nix | 121 ++++++++++++-------- 2 files changed, 74 insertions(+), 53 deletions(-) diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index f0d3051aa..855118a3b 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -160,10 +160,10 @@ let { config.clan.${serviceName} = lib.mkMerge ( [ - (globalConfig) - (lib.traceValSeq machineServiceConfig) + globalConfig + machineServiceConfig ] - ++ (roleServiceConfigs) + ++ roleServiceConfigs ); } ) diff --git a/lib/inventory/build-inventory/interface.nix b/lib/inventory/build-inventory/interface.nix index d4b26338d..dd20a676a 100644 --- a/lib/inventory/build-inventory/interface.nix +++ b/lib/inventory/build-inventory/interface.nix @@ -13,6 +13,20 @@ let type = types.nullOr types.str; }; }; + metaOptionsWith = name: { + name = lib.mkOption { + type = types.str; + default = name; + }; + description = lib.mkOption { + default = null; + type = types.nullOr types.str; + }; + icon = lib.mkOption { + default = null; + type = types.nullOr types.str; + }; + }; moduleConfig = lib.mkOption { default = { }; @@ -64,26 +78,30 @@ in machines = lib.mkOption { default = { }; type = types.attrsOf ( - types.submodule { - options = { - inherit (metaOptions) name description icon; - tags = lib.mkOption { + types.submodule ( + { name, ... }: + { + options = { + inherit (metaOptionsWith name) name description icon; - default = [ ]; - apply = lib.unique; - type = types.listOf types.str; + tags = lib.mkOption { + + default = [ ]; + apply = lib.unique; + type = types.listOf types.str; + }; + system = lib.mkOption { + default = null; + type = types.nullOr types.str; + }; + deploy.targetHost = lib.mkOption { + description = "Configuration for the deployment of the machine"; + default = null; + type = types.nullOr types.str; + }; }; - system = lib.mkOption { - default = null; - type = types.nullOr types.str; - }; - deploy.targetHost = lib.mkOption { - description = "Configuration for the deployment of the machine"; - default = null; - type = types.nullOr types.str; - }; - }; - } + } + ) ); }; @@ -91,38 +109,41 @@ in default = { }; type = types.attrsOf ( types.attrsOf ( - types.submodule { - options.meta = metaOptions; - options.imports = importsOption; - options.config = moduleConfig; - options.machines = lib.mkOption { - default = { }; - type = types.attrsOf ( - types.submodule { - options.imports = importsOption; - options.config = moduleConfig; - } - ); - }; - options.roles = lib.mkOption { - default = { }; - type = types.attrsOf ( - types.submodule { - options.machines = lib.mkOption { - default = [ ]; - type = types.listOf types.str; - }; - options.tags = lib.mkOption { - default = [ ]; - apply = lib.unique; - type = types.listOf types.str; - }; - options.config = moduleConfig; - options.imports = importsOption; - } - ); - }; - } + types.submodule ( + { name, ... }: + { + options.meta = metaOptionsWith name; + options.imports = importsOption; + options.config = moduleConfig; + options.machines = lib.mkOption { + default = { }; + type = types.attrsOf ( + types.submodule { + options.imports = importsOption; + options.config = moduleConfig; + } + ); + }; + options.roles = lib.mkOption { + default = { }; + type = types.attrsOf ( + types.submodule { + options.machines = lib.mkOption { + default = [ ]; + type = types.listOf types.str; + }; + options.tags = lib.mkOption { + default = [ ]; + apply = lib.unique; + type = types.listOf types.str; + }; + options.config = moduleConfig; + options.imports = importsOption; + } + ); + }; + } + ) ) ); };