diff --git a/lib/inventory/constraints/default.nix b/lib/inventory/constraints/default.nix index ed2764c8a..2f4ecd851 100644 --- a/lib/inventory/constraints/default.nix +++ b/lib/inventory/constraints/default.nix @@ -1,9 +1,12 @@ { - lib, - config, resolvedRoles, instanceName, moduleName, + allRoles, +}: +{ + lib, + config, ... }: let @@ -11,7 +14,7 @@ let in { imports = [ - ./interface.nix + (lib.modules.importApply ./interface.nix { inherit allRoles; }) # Role assertions { config.assertions = lib.foldlAttrs ( @@ -24,7 +27,7 @@ in "${moduleName}.${instanceName}.roles.${roleName}.min" = { assertion = memberCount >= roleConstraints.min; message = '' - The ${moduleName} module requires at least ${builtins.toString roleConstraints.min} members of the '${roleName}' role + The '${moduleName}' module requires at least ${builtins.toString roleConstraints.min} members of the '${roleName}' role but found '${builtins.toString memberCount}' members within instance '${instanceName}': ${lib.concatLines members} diff --git a/lib/inventory/constraints/interface.nix b/lib/inventory/constraints/interface.nix index 84d0e6f65..b94064ffe 100644 --- a/lib/inventory/constraints/interface.nix +++ b/lib/inventory/constraints/interface.nix @@ -1,7 +1,8 @@ +{ + allRoles, +}: { lib, - allRoles, - moduleName, ... }: let @@ -9,12 +10,6 @@ let rolesAttrs = builtins.groupBy lib.id allRoles; in { - options.serviceName = mkOption { - type = types.str; - default = moduleName; - readOnly = true; - visible = false; - }; options.roles = lib.mapAttrs ( _name: _: mkOption { diff --git a/lib/inventory/frontmatter/default.nix b/lib/inventory/frontmatter/default.nix index 243fb4c61..ce4a573b4 100644 --- a/lib/inventory/frontmatter/default.nix +++ b/lib/inventory/frontmatter/default.nix @@ -34,25 +34,33 @@ let allModules, }: lib.evalModules { - specialArgs = { - inherit moduleName resolvedRoles instanceName; - allRoles = getRoles "inventory.modules" allModules moduleName; - }; modules = [ (getFrontmatter allModules.${moduleName} moduleName) ./interface.nix + { + constraints.imports = [ + (lib.modules.importApply ../constraints { + inherit moduleName resolvedRoles instanceName; + allRoles = getRoles "inventory.modules" allModules moduleName; + }) + ]; + } ]; }; # For Documentation purposes only frontmatterOptions = (lib.evalModules { - specialArgs = { - moduleName = "{moduleName}"; - allRoles = [ "{roleName}" ]; - }; modules = [ ./interface.nix + { + constraints.imports = [ + (lib.modules.importApply ../constraints { + moduleName = "{moduleName}"; + allRoles = [ "{roleName}" ]; + }) + ]; + } ]; }).options; diff --git a/lib/inventory/frontmatter/interface.nix b/lib/inventory/frontmatter/interface.nix index 4c1a1623d..238f89101 100644 --- a/lib/inventory/frontmatter/interface.nix +++ b/lib/inventory/frontmatter/interface.nix @@ -1,6 +1,5 @@ { lib, - specialArgs, ... }: let @@ -76,9 +75,8 @@ in ``` ''; type = types.submoduleWith { - inherit specialArgs; modules = [ - ../constraints + ]; }; };