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;
|
type = types.str;
|
||||||
default = moduleName;
|
default = moduleName;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
visible = false;
|
||||||
};
|
};
|
||||||
options.roles = lib.mapAttrs (
|
options.roles = lib.mapAttrs (
|
||||||
_name: _:
|
_name: _:
|
||||||
@@ -37,24 +38,9 @@ in
|
|||||||
}
|
}
|
||||||
) rolesAttrs;
|
) rolesAttrs;
|
||||||
|
|
||||||
options.instances = mkOption {
|
|
||||||
default = { };
|
|
||||||
type = types.submoduleWith {
|
|
||||||
modules = [
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
max = mkOption {
|
|
||||||
type = types.nullOr types.int;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# The resulting assertions
|
# The resulting assertions
|
||||||
options.assertions = mkOption {
|
options.assertions = mkOption {
|
||||||
|
visible = false;
|
||||||
default = { };
|
default = { };
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.submoduleWith {
|
types.submoduleWith {
|
||||||
|
|||||||
@@ -5,16 +5,16 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
eval = import ./eval-clan-modules {
|
evalClan = import ./eval-clan-modules {
|
||||||
inherit clan-core lib;
|
inherit clan-core lib;
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit (eval) evalClanModules evalClanModulesWithRoles;
|
inherit (evalClan) evalClanModules evalClanModulesWithRoles;
|
||||||
buildClan = import ./build-clan { inherit lib nixpkgs clan-core; };
|
buildClan = import ./build-clan { inherit lib nixpkgs clan-core; };
|
||||||
facts = import ./facts.nix { inherit lib; };
|
facts = import ./facts.nix { inherit lib; };
|
||||||
inventory = import ./inventory { inherit lib clan-core; };
|
inventory = import ./inventory { inherit lib clan-core; };
|
||||||
jsonschema = import ./jsonschema { inherit lib; };
|
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 =
|
roles =
|
||||||
if builtins.elem "inventory" frontmatter.features or [ ] then
|
if builtins.elem "inventory" frontmatter.features or [ ] then
|
||||||
assert lib.isPath module;
|
assert lib.isPath module;
|
||||||
clan-core.lib.modules.getRoles' moduleName
|
clan-core.lib.modules.getRoles moduleName
|
||||||
else
|
else
|
||||||
[ ];
|
[ ];
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -1,8 +1,38 @@
|
|||||||
{ clan-core, lib }:
|
{ clan-core, lib }:
|
||||||
let
|
let
|
||||||
|
# Trim the .nix extension from a filename
|
||||||
trimExtension = name: builtins.substring 0 (builtins.stringLength name - 4) name;
|
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:
|
serviceName:
|
||||||
lib.mapAttrsToList (name: _value: trimExtension name) (
|
lib.mapAttrsToList (name: _value: trimExtension name) (
|
||||||
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (
|
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (
|
||||||
@@ -15,46 +45,9 @@ let
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
getConstraints =
|
getConstraints = modulename: (getFrontmatter modulename).constraints;
|
||||||
modulename:
|
|
||||||
let
|
|
||||||
eval = lib.evalModules {
|
|
||||||
specialArgs = {
|
|
||||||
allRoles = getRoles' modulename;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
./constraints/interface.nix
|
|
||||||
(getFrontmatter modulename).constraints
|
|
||||||
];
|
|
||||||
};
|
|
||||||
in
|
|
||||||
eval.config.roles;
|
|
||||||
|
|
||||||
checkConstraints =
|
checkConstraints = args: (evalFrontmatter args).config.constraints.assertions;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
getReadme =
|
getReadme =
|
||||||
modulename:
|
modulename:
|
||||||
@@ -97,10 +90,13 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit
|
inherit
|
||||||
|
evalFrontmatter
|
||||||
|
frontmatterDocsOptions
|
||||||
|
|
||||||
getFrontmatter
|
getFrontmatter
|
||||||
getReadme
|
getReadme
|
||||||
getRoles'
|
|
||||||
getConstraints
|
getConstraints
|
||||||
checkConstraints
|
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:
|
acc2: instanceName: serviceConfig:
|
||||||
|
|
||||||
let
|
let
|
||||||
roles = clan-core.lib.modules.getRoles' serviceName;
|
roles = clan-core.lib.modules.getRoles serviceName;
|
||||||
|
|
||||||
resolvedRoles = lib.genAttrs roles (
|
resolvedRoles = lib.genAttrs roles (
|
||||||
roleName:
|
roleName:
|
||||||
@@ -152,7 +152,6 @@ let
|
|||||||
constraintAssertions = clan-core.lib.modules.checkConstraints {
|
constraintAssertions = clan-core.lib.modules.checkConstraints {
|
||||||
moduleName = serviceName;
|
moduleName = serviceName;
|
||||||
inherit resolvedRoles instanceName;
|
inherit resolvedRoles instanceName;
|
||||||
instanceNames = builtins.attrNames serviceConfigs;
|
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
if (nonExistingRoles != [ ]) then
|
if (nonExistingRoles != [ ]) then
|
||||||
|
|||||||
Reference in New Issue
Block a user