chore(inventory/instances): don't eagerly test the service modules _class
This commit is contained in:
@@ -120,22 +120,13 @@ let
|
|||||||
# TODO: Eagerly check the _class of the resolved module
|
# TODO: Eagerly check the _class of the resolved module
|
||||||
importedModulesEvaluated = lib.mapAttrs (
|
importedModulesEvaluated = lib.mapAttrs (
|
||||||
_module_ident: instances:
|
_module_ident: instances:
|
||||||
let
|
|
||||||
matchedClass = "clan.service";
|
|
||||||
instance = (builtins.head instances).instance;
|
|
||||||
classCheckedModule =
|
|
||||||
if instance.moduleClass == matchedClass then
|
|
||||||
instance.resolvedModule
|
|
||||||
else
|
|
||||||
(throw ''Module '${instance.module.name}' is not a valid '${matchedClass}' module. Got module with class:${builtins.toJSON instance.moduleClass}'');
|
|
||||||
in
|
|
||||||
(lib.evalModules {
|
(lib.evalModules {
|
||||||
class = matchedClass;
|
class = "clan.service";
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
./service-module.nix
|
./service-module.nix
|
||||||
# Import the resolved module
|
# Import the resolved module.
|
||||||
classCheckedModule
|
(builtins.head instances).instance.resolvedModule
|
||||||
]
|
]
|
||||||
# Include all the instances that correlate to the resolved module
|
# Include all the instances that correlate to the resolved module
|
||||||
++ (builtins.map (v: {
|
++ (builtins.map (v: {
|
||||||
|
|||||||
@@ -53,13 +53,4 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
# Currently this should fail
|
|
||||||
# TODO: Can we implement a default wrapper to make migration easy?
|
|
||||||
test_import_local_legacy_module = {
|
|
||||||
expr = (resolve { name = "B"; }).allMachines;
|
|
||||||
expectedError = {
|
|
||||||
type = "ThrownError";
|
|
||||||
msg = "Module 'B' is not a valid 'clan.service' module.*";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,21 +66,32 @@ let
|
|||||||
allModules.${serviceName}
|
allModules.${serviceName}
|
||||||
or (throw "(Legacy) ClanModule not found: '${serviceName}'. Make sure the module is added to ${scope}");
|
or (throw "(Legacy) ClanModule not found: '${serviceName}'. Make sure the module is added to ${scope}");
|
||||||
moduleType = (lib.typeOf module);
|
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} ";
|
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";
|
modulePath = lib.seq checked module + "/roles";
|
||||||
checkedPath = if builtins.pathExists modulePath then modulePath else throw ''
|
checkedPath =
|
||||||
(Legacy) ClanModule must have a 'roles' directory'
|
if builtins.pathExists modulePath then
|
||||||
|
modulePath
|
||||||
|
else
|
||||||
|
throw ''
|
||||||
|
(Legacy) ClanModule must have a 'roles' directory'
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
- Provide a 'roles' subdirectory
|
- Provide a 'roles' subdirectory
|
||||||
- Use the newer 'clan.service' modules. (Recommended)
|
- Use the newer 'clan.service' modules. (Recommended)
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
lib.seq checkedPath lib.mapAttrsToList (name: _value: trimExtension name) (
|
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 (checkedPath)
|
||||||
checkedPath
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ in
|
|||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
legacyModule = {
|
legacyModule = {
|
||||||
isClanModule = false;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user