Merge pull request 'refactor(clan.service): make evalClanService a standalone function to interact with standalone modules' (#3444) from hsjobeki/clan-core:clan-services-4 into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3444
This commit is contained in:
@@ -64,7 +64,33 @@ in
|
||||
self'.legacyPackages.homeConfigurations or { }
|
||||
);
|
||||
in
|
||||
nixosTests // flakeOutputs;
|
||||
nixosTests
|
||||
// flakeOutputs
|
||||
// {
|
||||
# TODO: Automatically provide this check to downstream users to check their modules
|
||||
clan-modules-json-compatible =
|
||||
let
|
||||
allSchemas = lib.mapAttrs (
|
||||
_n: m:
|
||||
let
|
||||
schema =
|
||||
(self.clanLib.inventory.evalClanService {
|
||||
modules = [ m ];
|
||||
key = "checks";
|
||||
}).config.result.api.schema;
|
||||
in
|
||||
schema
|
||||
) self.clan.modules;
|
||||
in
|
||||
pkgs.runCommand "combined-result"
|
||||
{
|
||||
schemaFile = builtins.toFile "schemas.json" (builtins.toJSON allSchemas);
|
||||
}
|
||||
''
|
||||
mkdir -p $out
|
||||
cat $schemaFile > $out/allSchemas.json
|
||||
'';
|
||||
};
|
||||
legacyPackages = {
|
||||
nixosTests =
|
||||
let
|
||||
|
||||
@@ -13,6 +13,9 @@ in
|
||||
clan.inventory.modules = {
|
||||
hello-world = module;
|
||||
};
|
||||
clan.modules = {
|
||||
hello-world = module;
|
||||
};
|
||||
perSystem =
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
{ lib, clanLib }:
|
||||
let
|
||||
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
||||
in
|
||||
{
|
||||
inherit (services) evalClanService mapInstances;
|
||||
inherit (import ./build-inventory { inherit lib clanLib; }) buildInventory;
|
||||
interface = ./build-inventory/interface.nix;
|
||||
mapInstances = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
||||
# Returns the list of machine names
|
||||
# { ... } -> [ string ]
|
||||
resolveTags =
|
||||
|
||||
@@ -14,13 +14,31 @@
|
||||
clanLib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
evalClanService =
|
||||
{ modules, key }:
|
||||
(lib.evalModules {
|
||||
class = "clan.service";
|
||||
modules = [
|
||||
./service-module.nix
|
||||
# feature modules
|
||||
(lib.modules.importApply ./api-feature.nix {
|
||||
inherit clanLib;
|
||||
attrName = key;
|
||||
})
|
||||
] ++ modules;
|
||||
});
|
||||
in
|
||||
{
|
||||
inherit evalClanService;
|
||||
mapInstances =
|
||||
{
|
||||
# This is used to resolve the module imports from 'flake.inputs'
|
||||
flakeInputs,
|
||||
# The clan inventory
|
||||
inventory,
|
||||
}:
|
||||
let
|
||||
}:
|
||||
let
|
||||
# machineHasTag = machineName: tagName: lib.elem tagName inventory.machines.${machineName}.tags;
|
||||
|
||||
# map the instances into the module
|
||||
@@ -119,25 +137,17 @@ let
|
||||
# TODO: Eagerly check the _class of the resolved module
|
||||
importedModulesEvaluated = lib.mapAttrs (
|
||||
module_ident: instances:
|
||||
(lib.evalModules {
|
||||
class = "clan.service";
|
||||
evalClanService {
|
||||
key = module_ident;
|
||||
modules =
|
||||
[
|
||||
./service-module.nix
|
||||
# Import the resolved module.
|
||||
(builtins.head instances).instance.resolvedModule
|
||||
|
||||
# feature modules
|
||||
(lib.modules.importApply ./api-feature.nix {
|
||||
inherit clanLib;
|
||||
attrName = module_ident;
|
||||
})
|
||||
]
|
||||
# Include all the instances that correlate to the resolved module
|
||||
] # Include all the instances that correlate to the resolved module
|
||||
++ (builtins.map (v: {
|
||||
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
||||
}) instances);
|
||||
})
|
||||
}
|
||||
) grouped;
|
||||
|
||||
# Group the instances by the module they resolve to
|
||||
@@ -168,8 +178,8 @@ let
|
||||
machineName: result: acc.${machineName} or [ ] ++ [ result.nixosModule ]
|
||||
) eval.config.result.final
|
||||
) { } importedModulesEvaluated;
|
||||
in
|
||||
{
|
||||
in
|
||||
{
|
||||
inherit
|
||||
importedModuleWithInstances
|
||||
grouped
|
||||
@@ -177,4 +187,6 @@ in
|
||||
allMachines
|
||||
importedModulesEvaluated
|
||||
;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user