Merge pull request 'modules/frontmatter: init module interface as source of frontmatter' (#2420) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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; };
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
;
|
||||
}
|
||||
58
lib/frontmatter/interface.nix
Normal file
58
lib/frontmatter/interface.nix
Normal file
@@ -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
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user