refactor(clan.service): make evalClanService a standalone function to interact with standalone modules
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
{ lib, clanLib }:
|
{ lib, clanLib }:
|
||||||
|
let
|
||||||
|
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
||||||
|
in
|
||||||
{
|
{
|
||||||
|
inherit (services) evalClanService mapInstances;
|
||||||
inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory;
|
inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory;
|
||||||
interface = ./build-inventory/interface.nix;
|
interface = ./build-inventory/interface.nix;
|
||||||
mapInstances = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
|
||||||
# Returns the list of machine names
|
# Returns the list of machine names
|
||||||
# { ... } -> [ string ]
|
# { ... } -> [ string ]
|
||||||
resolveTags =
|
resolveTags =
|
||||||
|
|||||||
@@ -14,6 +14,25 @@
|
|||||||
clanLib,
|
clanLib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
evalClanService =
|
||||||
|
{ modules, id }:
|
||||||
|
(lib.evalModules {
|
||||||
|
class = "clan.service";
|
||||||
|
modules = [
|
||||||
|
./service-module.nix
|
||||||
|
|
||||||
|
# feature modules
|
||||||
|
(lib.modules.importApply ./api-feature.nix {
|
||||||
|
inherit clanLib;
|
||||||
|
attrName = id;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit evalClanService;
|
||||||
|
mapInstances =
|
||||||
{
|
{
|
||||||
# This is used to resolve the module imports from 'flake.inputs'
|
# This is used to resolve the module imports from 'flake.inputs'
|
||||||
flakeInputs,
|
flakeInputs,
|
||||||
@@ -119,25 +138,17 @@ 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:
|
||||||
(lib.evalModules {
|
evalClanService {
|
||||||
class = "clan.service";
|
id = module_ident;
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
./service-module.nix
|
|
||||||
# Import the resolved module.
|
# Import the resolved module.
|
||||||
(builtins.head instances).instance.resolvedModule
|
(builtins.head instances).instance.resolvedModule
|
||||||
|
] # Include all the instances that correlate to the resolved module
|
||||||
# feature modules
|
|
||||||
(lib.modules.importApply ./api-feature.nix {
|
|
||||||
inherit clanLib;
|
|
||||||
attrName = module_ident;
|
|
||||||
})
|
|
||||||
]
|
|
||||||
# Include all the instances that correlate to the resolved module
|
|
||||||
++ (builtins.map (v: {
|
++ (builtins.map (v: {
|
||||||
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
||||||
}) instances);
|
}) instances);
|
||||||
})
|
}
|
||||||
) grouped;
|
) grouped;
|
||||||
|
|
||||||
# Group the instances by the module they resolve to
|
# Group the instances by the module they resolve to
|
||||||
@@ -177,4 +188,6 @@ in
|
|||||||
allMachines
|
allMachines
|
||||||
importedModulesEvaluated
|
importedModulesEvaluated
|
||||||
;
|
;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user