diff --git a/checks/flake-module.nix b/checks/flake-module.nix index 5e47cdccd..fec530b8b 100644 --- a/checks/flake-module.nix +++ b/checks/flake-module.nix @@ -21,6 +21,7 @@ in pkgs, lib, self', + system, ... }: { @@ -83,7 +84,7 @@ in schema = (self.clanLib.inventory.evalClanService { modules = [ m ]; - key = "checks"; + prefix = [ "checks" system ]; }).config.result.api.schema; in schema diff --git a/clanServices/hello-world/default.nix b/clanServices/hello-world/default.nix index 7a835bede..86bfbdb1e 100644 --- a/clanServices/hello-world/default.nix +++ b/clanServices/hello-world/default.nix @@ -4,7 +4,15 @@ _class = "clan.service"; manifest.name = "clan-core/hello-word"; - roles.peer = { }; + roles.peer = { + interface = + { lib, ... }: + { + options.foo = lib.mkOption { + type = lib.types.str; + }; + }; + }; perMachine = { machine, ... }: diff --git a/clanServices/hello-world/flake-module.nix b/clanServices/hello-world/flake-module.nix index 9a1c14a27..0c85e0630 100644 --- a/clanServices/hello-world/flake-module.nix +++ b/clanServices/hello-world/flake-module.nix @@ -50,6 +50,7 @@ in hello-service = import ./tests/vm/default.nix { inherit module; inherit self inputs pkgs; + # clanLib is exposed from inputs.clan-core clanLib = self.clanLib; }; }; diff --git a/lib/build-clan/interface.nix b/lib/build-clan/interface.nix index db090ec2b..fc61197e7 100644 --- a/lib/build-clan/interface.nix +++ b/lib/build-clan/interface.nix @@ -10,6 +10,11 @@ let in { options = { + _prefix = lib.mkOption { + type = types.listOf types.str; + internal = true; + default = [ ]; + }; self = lib.mkOption { type = types.raw; default = self; diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index acb7a2519..169c058e0 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -44,6 +44,7 @@ let buildInventory { inherit inventory directory; flakeInputs = config.self.inputs; + prefix = config._prefix ++ [ "inventoryClass" ]; } ); diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index 1a4997873..0236eb2c5 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -12,8 +12,10 @@ let inventory, directory, flakeInputs, + prefix ? [ ], }: (lib.evalModules { + # TODO: remove clanLib from specialArgs specialArgs = { inherit clanLib; }; @@ -24,13 +26,16 @@ let # config.distributedServices.allMachines.${name} or [ ]; { config, ... }: { + distributedServices = clanLib.inventory.mapInstances { inherit (config) inventory; inherit flakeInputs; + prefix = prefix ++ [ "distributedServices" ]; }; machines = lib.mapAttrs (_machineName: v: { machineImports = v; }) config.distributedServices.allMachines; + } ) ]; diff --git a/lib/inventory/distributed-service/api-feature.nix b/lib/inventory/distributed-service/api-feature.nix index 1266bb68a..f745251f0 100644 --- a/lib/inventory/distributed-service/api-feature.nix +++ b/lib/inventory/distributed-service/api-feature.nix @@ -1,7 +1,7 @@ # This module enables itself if # manifest.features.API = true # It converts the roles.interface to a json-schema -{ clanLib, attrName }: +{ clanLib, prefix }: let converter = clanLib.jsonschema { includeDefaults = true; @@ -45,7 +45,7 @@ in To see the evaluation problem run - nix eval .#clanInternals.inventoryClass.distributedServices.importedModulesEvaluated.${attrName}.config.result.api.schema.${roleName} + nix eval .#${lib.concatStringsSep "." prefix}.config.result.api.schema.${roleName} ''; assertion = (builtins.tryEval (lib.deepSeq config.result.api.schema.${roleName} true)).success; }; diff --git a/lib/inventory/distributed-service/inventory-adapter.nix b/lib/inventory/distributed-service/inventory-adapter.nix index e899564c8..bbedc467f 100644 --- a/lib/inventory/distributed-service/inventory-adapter.nix +++ b/lib/inventory/distributed-service/inventory-adapter.nix @@ -16,15 +16,14 @@ }: let evalClanService = - { modules, key }: + { modules, prefix }: (lib.evalModules { class = "clan.service"; modules = [ ./service-module.nix # feature modules (lib.modules.importApply ./api-feature.nix { - inherit clanLib; - attrName = key; + inherit clanLib prefix; }) ] ++ modules; }); @@ -37,6 +36,7 @@ in flakeInputs, # The clan inventory inventory, + prefix ? [ ], }: let # machineHasTag = machineName: tagName: lib.elem tagName inventory.machines.${machineName}.tags; @@ -138,7 +138,7 @@ in importedModulesEvaluated = lib.mapAttrs ( module_ident: instances: evalClanService { - key = module_ident; + prefix = prefix ++ [ module_ident ]; modules = [ # Import the resolved module. diff --git a/lib/test/default.nix b/lib/test/default.nix index 05d4e5ffe..3849f2006 100644 --- a/lib/test/default.nix +++ b/lib/test/default.nix @@ -22,6 +22,9 @@ in pkgs, self, useContainers ? true, + # Displayed for better error messages, otherwise the placeholder + system ? "", + attrName ? "", ... }: let @@ -60,6 +63,15 @@ in }; modules = [ clanLib.buildClanModule.flakePartsModule + { + _prefix = [ + "checks" + system + attrName + "config" + "clan" + ]; + } ]; }; };