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/distributed-service/manifest/default.nix b/lib/inventory/distributed-service/manifest/default.nix new file mode 100644 index 000000000..8e174b652 --- /dev/null +++ b/lib/inventory/distributed-service/manifest/default.nix @@ -0,0 +1,78 @@ +{ lib, config, ... }: +let + inherit (lib) mkOption; + inherit (lib) types; +in +{ + options = { + name = mkOption { + description = '' + The name of the module + + Mainly used to create an error context while evaluating. + This helps backtracking which module was included; And where an error came from originally. + ''; + type = types.str; + }; + description = mkOption { + type = types.str; + description = '' + A Short description of the module. + ''; + defaultText = "Short description"; + default = config.name; + }; + categories = mkOption { + default = [ "Uncategorized" ]; + description = '' + Categories are used for Grouping and searching. + + While initial oriented on [freedesktop](https://specifications.freedesktop.org/menu-spec/latest/category-registry.html) the following categories are allowed + ''; + type = types.listOf ( + types.enum [ + "AudioVideo" + "Audio" + "Video" + "Development" + "Education" + "Game" + "Graphics" + "Social" + "Network" + "Office" + "Science" + "System" + "Settings" + "Utility" + "Uncategorized" + ] + ); + }; + + features = mkOption { + description = '' + Enable built-in features for the module + + See the documentation for each feature: + - API + ''; + type = types.submoduleWith { + modules = [ + { + options.API = mkOption { + type = types.bool; + # This is read only, because we don't support turning it off yet + readOnly = true; + default = true; + description = '' + Enables automatic API schema conversion for the interface of this module. + ''; + }; + } + ]; + }; + default = { }; + }; + }; +} diff --git a/lib/inventory/distributed-service/service-module.nix b/lib/inventory/distributed-service/service-module.nix index 89a3eeeb2..e92b53da1 100644 --- a/lib/inventory/distributed-service/service-module.nix +++ b/lib/inventory/distributed-service/service-module.nix @@ -232,43 +232,7 @@ in description = "Meta information about this module itself"; type = submoduleWith { modules = [ - { - options = { - name = mkOption { - description = '' - The name of the module - - Mainly used to create an error context while evaluating. - This helps backtracking which module was included; And where an error came from originally. - ''; - type = types.str; - }; - features = mkOption { - description = '' - Enable built-in features for the module - - See the documentation for each feature: - - API - ''; - type = types.submoduleWith { - modules = [ - { - options.API = mkOption { - type = types.bool; - # This is read only, because we don't support turning it off yet - readOnly = true; - default = true; - description = '' - Enables automatic API schema conversion for the interface of this module. - ''; - }; - } - ]; - }; - default = { }; - }; - }; - } + ./manifest/default.nix ]; }; }; 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 + ]; }; };