chore(inventory/services): dont check _class of legacy clanModules.
Let the module system handle the error. Once we shift to deferred modules, things get more complicated and we cannot check the module class eagerly
This commit is contained in:
@@ -56,7 +56,7 @@ let
|
|||||||
assertions = { };
|
assertions = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
legacyResolveImports =
|
resolveImports =
|
||||||
{
|
{
|
||||||
supportedRoles,
|
supportedRoles,
|
||||||
resolvedRolesPerInstance,
|
resolvedRolesPerInstance,
|
||||||
@@ -168,27 +168,7 @@ in
|
|||||||
./roles.nix
|
./roles.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
isClanModule =
|
machineImports = resolveImports {
|
||||||
let
|
|
||||||
firstRole = import (getRoleFile (builtins.head config.supportedRoles));
|
|
||||||
loadModuleForClassCheck =
|
|
||||||
m:
|
|
||||||
if lib.isFunction m then
|
|
||||||
let
|
|
||||||
args = lib.functionArgs m;
|
|
||||||
in
|
|
||||||
m args
|
|
||||||
else
|
|
||||||
m;
|
|
||||||
module = loadModuleForClassCheck (firstRole);
|
|
||||||
in
|
|
||||||
if (module) ? _class then module._class == "clan" else false;
|
|
||||||
# The actual result
|
|
||||||
machineImports =
|
|
||||||
if config.isClanModule then
|
|
||||||
throw "Clan modules are not supported yet."
|
|
||||||
else
|
|
||||||
legacyResolveImports {
|
|
||||||
supportedRoles = config.supportedRoles;
|
supportedRoles = config.supportedRoles;
|
||||||
resolvedRolesPerInstance = config.resolvedRolesPerInstance;
|
resolvedRolesPerInstance = config.resolvedRolesPerInstance;
|
||||||
inherit
|
inherit
|
||||||
|
|||||||
@@ -54,9 +54,6 @@ in
|
|||||||
matchedRoles = mkOption {
|
matchedRoles = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
};
|
};
|
||||||
isClanModule = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
};
|
|
||||||
machinesRoles = mkOption {
|
machinesRoles = mkOption {
|
||||||
type = types.attrsOf (types.listOf types.str);
|
type = types.attrsOf (types.listOf types.str);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ in
|
|||||||
{
|
{
|
||||||
# Roles resolution
|
# Roles resolution
|
||||||
# : List String
|
# : List String
|
||||||
supportedRoles = clanLib.modules.getRoles inventory.modules serviceName;
|
supportedRoles = clanLib.modules.getRoles "inventory.modules" inventory.modules serviceName;
|
||||||
matchedRoles = builtins.attrNames (
|
matchedRoles = builtins.attrNames (
|
||||||
lib.filterAttrs (_: ms: builtins.elem machineName ms) config.machinesRoles
|
lib.filterAttrs (_: ms: builtins.elem machineName ms) config.machinesRoles
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -74,7 +74,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;
|
||||||
clanLib.modules.getRoles allModules moduleName
|
clan-core.lib.modules.getRoles "Documentation: inventory.modules" allModules moduleName
|
||||||
else
|
else
|
||||||
[ ];
|
[ ];
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ let
|
|||||||
lib.evalModules {
|
lib.evalModules {
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit moduleName resolvedRoles instanceName;
|
inherit moduleName resolvedRoles instanceName;
|
||||||
allRoles = getRoles allModules moduleName;
|
allRoles = getRoles "inventory.modules" allModules moduleName;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
(getFrontmatter allModules.${moduleName} moduleName)
|
(getFrontmatter allModules.${moduleName} moduleName)
|
||||||
@@ -56,15 +56,30 @@ let
|
|||||||
];
|
];
|
||||||
}).options;
|
}).options;
|
||||||
|
|
||||||
|
# This is a legacy function
|
||||||
|
# Old modules needed to define their roles by directory
|
||||||
|
# This means if this function gets anything other than a string/path it will throw
|
||||||
getRoles =
|
getRoles =
|
||||||
allModules: serviceName:
|
scope: allModules: serviceName:
|
||||||
lib.mapAttrsToList (name: _value: trimExtension name) (
|
let
|
||||||
|
module =
|
||||||
|
allModules.${serviceName}
|
||||||
|
or (throw "(Legacy) ClanModule not found: '${serviceName}'. Make sure the module is added to ${scope}");
|
||||||
|
moduleType = (lib.typeOf module);
|
||||||
|
checked = if builtins.elem moduleType ["string" "path"] then true else throw "(Legacy) ClanModule must be a 'path' or 'string' pointing to a directory: Got 'typeOf inventory.modules.${serviceName}' => ${moduleType} ";
|
||||||
|
modulePath = lib.seq checked module + "/roles";
|
||||||
|
checkedPath = if builtins.pathExists modulePath then modulePath else throw ''
|
||||||
|
(Legacy) ClanModule must have a 'roles' directory'
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
- Provide a 'roles' subdirectory
|
||||||
|
- Use the newer 'clan.service' modules. (Recommended)
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
lib.seq checkedPath 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) (
|
||||||
builtins.readDir (
|
builtins.readDir (
|
||||||
if allModules ? ${serviceName} then
|
checkedPath
|
||||||
allModules.${serviceName} + "/roles"
|
|
||||||
else
|
|
||||||
throw "ClanModule not found: '${serviceName}'. Make sure the module is added in the 'clanModules' attribute of clan-core."
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user