diff --git a/lib/constraints/interface.nix b/lib/constraints/interface.nix index 006772fa2..38a26296b 100644 --- a/lib/constraints/interface.nix +++ b/lib/constraints/interface.nix @@ -13,6 +13,7 @@ in type = types.str; default = moduleName; readOnly = true; + visible = false; }; options.roles = lib.mapAttrs ( _name: _: @@ -37,24 +38,9 @@ in } ) rolesAttrs; - options.instances = mkOption { - default = { }; - type = types.submoduleWith { - modules = [ - { - options = { - max = mkOption { - type = types.nullOr types.int; - default = null; - }; - }; - } - ]; - }; - }; - # The resulting assertions options.assertions = mkOption { + visible = false; default = { }; type = types.attrsOf ( types.submoduleWith { diff --git a/lib/default.nix b/lib/default.nix index 530ddd620..e2c1f01d7 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,16 +5,16 @@ ... }: let - eval = import ./eval-clan-modules { + evalClan = import ./eval-clan-modules { inherit clan-core lib; pkgs = nixpkgs.legacyPackages.x86_64-linux; }; in { - inherit (eval) evalClanModules evalClanModulesWithRoles; + inherit (evalClan) evalClanModules evalClanModulesWithRoles; buildClan = import ./build-clan { inherit lib nixpkgs clan-core; }; facts = import ./facts.nix { inherit lib; }; inventory = import ./inventory { inherit lib clan-core; }; jsonschema = import ./jsonschema { inherit lib; }; - modules = import ./description.nix { inherit clan-core lib; }; + modules = import ./frontmatter { inherit clan-core lib; }; } diff --git a/lib/eval-clan-modules/default.nix b/lib/eval-clan-modules/default.nix index c20fe8037..cfea864f2 100644 --- a/lib/eval-clan-modules/default.nix +++ b/lib/eval-clan-modules/default.nix @@ -62,7 +62,7 @@ let roles = if builtins.elem "inventory" frontmatter.features or [ ] then assert lib.isPath module; - clan-core.lib.modules.getRoles' moduleName + clan-core.lib.modules.getRoles moduleName else [ ]; in diff --git a/lib/description.nix b/lib/frontmatter/default.nix similarity index 73% rename from lib/description.nix rename to lib/frontmatter/default.nix index 68a114d81..945bc813c 100644 --- a/lib/description.nix +++ b/lib/frontmatter/default.nix @@ -1,8 +1,38 @@ { clan-core, lib }: let + # Trim the .nix extension from a filename trimExtension = name: builtins.substring 0 (builtins.stringLength name - 4) name; - getRoles' = + evalFrontmatter = + { + moduleName, + instanceName, + resolvedRoles, + }: + lib.evalModules { + specialArgs = { + inherit moduleName resolvedRoles instanceName; + allRoles = getRoles moduleName; + }; + modules = [ + (getFrontmatter moduleName) + ./interface.nix + ]; + }; + + frontmatterDocsOptions = + lib.optionAttrSetToDocList + (lib.evalModules { + specialArgs = { + moduleName = "{moduleName}"; + allRoles = [ "{roleName}" ]; + }; + modules = [ + ./interface.nix + ]; + }).options; + + getRoles = serviceName: lib.mapAttrsToList (name: _value: trimExtension name) ( lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) ( @@ -15,46 +45,9 @@ let ) ); - getConstraints = - modulename: - let - eval = lib.evalModules { - specialArgs = { - allRoles = getRoles' modulename; - }; - modules = [ - ./constraints/interface.nix - (getFrontmatter modulename).constraints - ]; - }; - in - eval.config.roles; + getConstraints = modulename: (getFrontmatter modulename).constraints; - checkConstraints = - { - moduleName, - resolvedRoles, - instanceNames, - instanceName, - }: - let - eval = lib.evalModules { - specialArgs = { - inherit - moduleName - instanceNames - instanceName - resolvedRoles - ; - allRoles = getRoles' moduleName; - }; - modules = [ - ./constraints/default.nix - ((getFrontmatter moduleName).constraints or { }) - ]; - }; - in - eval.config.assertions; + checkConstraints = args: (evalFrontmatter args).config.constraints.assertions; getReadme = modulename: @@ -97,10 +90,13 @@ let in { inherit + evalFrontmatter + frontmatterDocsOptions + getFrontmatter getReadme - getRoles' getConstraints checkConstraints + getRoles ; } diff --git a/lib/frontmatter/interface.nix b/lib/frontmatter/interface.nix new file mode 100644 index 000000000..c8ecc7a81 --- /dev/null +++ b/lib/frontmatter/interface.nix @@ -0,0 +1,58 @@ +{ + lib, + specialArgs, + ... +}: +let + inherit (lib) mkOption types; +in +{ + options = { + description = mkOption { + type = types.str; + description = '' + + ''; + }; + categories = mkOption { + default = [ "Uncategorized" ]; + type = types.listOf ( + types.enum [ + "AudioVideo" + "Audio" + "Video" + "Development" + "Education" + "Game" + "Graphics" + "Social" + "Network" + "Office" + "Science" + "System" + "Settings" + "Utility" + "Uncategorized" + ] + ); + }; + features = mkOption { + default = [ ]; + type = types.listOf ( + types.enum [ + "inventory" + ] + ); + }; + + constraints = mkOption { + default = { }; + type = types.submoduleWith { + inherit specialArgs; + modules = [ + ../constraints + ]; + }; + }; + }; +} diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index fb0d4f60a..9fb5f965d 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -94,7 +94,7 @@ let acc2: instanceName: serviceConfig: let - roles = clan-core.lib.modules.getRoles' serviceName; + roles = clan-core.lib.modules.getRoles serviceName; resolvedRoles = lib.genAttrs roles ( roleName: @@ -152,7 +152,6 @@ let constraintAssertions = clan-core.lib.modules.checkConstraints { moduleName = serviceName; inherit resolvedRoles instanceName; - instanceNames = builtins.attrNames serviceConfigs; }; in if (nonExistingRoles != [ ]) then