Merge pull request 'refactor: unify evalClanService with evalService' (#4106) from hsjobeki/eval service into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4106
This commit is contained in:
@@ -81,7 +81,7 @@ in
|
|||||||
_n: m:
|
_n: m:
|
||||||
let
|
let
|
||||||
schema =
|
schema =
|
||||||
(self.clanLib.inventory.evalClanService {
|
(self.clanLib.evalService {
|
||||||
modules = [ m ];
|
modules = [ m ];
|
||||||
prefix = [
|
prefix = [
|
||||||
"checks"
|
"checks"
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
clanModulesViaService = lib.mapAttrs (
|
clanModulesViaService = lib.mapAttrs (
|
||||||
_moduleName: moduleValue:
|
_moduleName: moduleValue:
|
||||||
let
|
let
|
||||||
evaluatedService = clan-core.clanLib.inventory.evalClanService {
|
evaluatedService = clan-core.clanLib.evalService {
|
||||||
modules = [ moduleValue ];
|
modules = [ moduleValue ];
|
||||||
prefix = [ ];
|
prefix = [ ];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,22 +23,19 @@
|
|||||||
|
|
||||||
baseHref = "/options-page/";
|
baseHref = "/options-page/";
|
||||||
|
|
||||||
evalService =
|
getRoles =
|
||||||
serviceModule:
|
module:
|
||||||
lib.evalModules {
|
(clanLib.evalService {
|
||||||
modules = [
|
modules = [ module ];
|
||||||
{
|
prefix = [ ];
|
||||||
imports = [
|
}).config.roles;
|
||||||
serviceModule
|
|
||||||
../../../lib/modules/inventory/distributed-service/service-module.nix
|
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
getRoles = module: (evalService module).config.roles;
|
getManifest =
|
||||||
|
module:
|
||||||
getManifest = module: (evalService module).config.manifest;
|
(clanLib.evalService {
|
||||||
|
modules = [ module ];
|
||||||
|
prefix = [ ];
|
||||||
|
}).config.manifest;
|
||||||
|
|
||||||
loadFile = file: if builtins.pathExists file then builtins.readFile file else "";
|
loadFile = file: if builtins.pathExists file then builtins.readFile file else "";
|
||||||
|
|
||||||
|
|||||||
@@ -20,22 +20,7 @@ lib.fix (clanLib: {
|
|||||||
clan-core = self;
|
clan-core = self;
|
||||||
inherit nixpkgs nix-darwin;
|
inherit nixpkgs nix-darwin;
|
||||||
};
|
};
|
||||||
evalServiceSchema =
|
evalService = clanLib.callLib ./modules/inventory/distributed-service/evalService.nix { };
|
||||||
self:
|
|
||||||
{
|
|
||||||
moduleSpec,
|
|
||||||
flakeInputs ? self.inputs,
|
|
||||||
localModuleSet ? self.clan.modules,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
resolvedModule = clanLib.inventory.resolveModule {
|
|
||||||
inherit moduleSpec flakeInputs localModuleSet;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
(clanLib.inventory.evalClanService {
|
|
||||||
modules = [ resolvedModule ];
|
|
||||||
prefix = [ ];
|
|
||||||
}).config.result.api.schema;
|
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# ClanLib functions
|
# ClanLib functions
|
||||||
evalClan = clanLib.callLib ./modules/inventory/eval-clan-modules { };
|
evalClan = clanLib.callLib ./modules/inventory/eval-clan-modules { };
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ let
|
|||||||
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit (services) evalClanService mapInstances resolveModule;
|
inherit (services) mapInstances;
|
||||||
interface = {
|
interface = {
|
||||||
_file = "clanLib.inventory.interface";
|
_file = "clanLib.inventory.interface";
|
||||||
imports = [
|
imports = [
|
||||||
|
|||||||
30
lib/modules/inventory/distributed-service/evalService.nix
Normal file
30
lib/modules/inventory/distributed-service/evalService.nix
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
Example usage:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
evalService = import /this/file.nix { inherit lib clanLib; };
|
||||||
|
result = evalService { modules = []; prefix = []; };
|
||||||
|
|
||||||
|
=> result.config
|
||||||
|
=> result.options
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
{ lib, clanLib }:
|
||||||
|
# <lambda evalService>
|
||||||
|
{ modules, prefix }:
|
||||||
|
lib.evalModules {
|
||||||
|
class = "clan.service";
|
||||||
|
specialArgs._ctx = prefix;
|
||||||
|
modules =
|
||||||
|
[
|
||||||
|
# Base module
|
||||||
|
./service-module.nix
|
||||||
|
# Feature modules
|
||||||
|
(lib.modules.importApply ./api-feature.nix {
|
||||||
|
inherit clanLib prefix;
|
||||||
|
})
|
||||||
|
]
|
||||||
|
++
|
||||||
|
# Modules of caller
|
||||||
|
modules;
|
||||||
|
}
|
||||||
@@ -15,67 +15,9 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
evalClanService =
|
resolveModule = import ./resolveModule.nix { inherit lib; };
|
||||||
{ modules, prefix }:
|
|
||||||
(lib.evalModules {
|
|
||||||
class = "clan.service";
|
|
||||||
specialArgs._ctx = prefix;
|
|
||||||
modules = [
|
|
||||||
./service-module.nix
|
|
||||||
# feature modules
|
|
||||||
(lib.modules.importApply ./api-feature.nix {
|
|
||||||
inherit clanLib prefix;
|
|
||||||
})
|
|
||||||
] ++ modules;
|
|
||||||
});
|
|
||||||
|
|
||||||
resolveModule =
|
|
||||||
{
|
|
||||||
moduleSpec,
|
|
||||||
flakeInputs,
|
|
||||||
localModuleSet,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
# TODO:
|
|
||||||
resolvedModuleSet =
|
|
||||||
# If the module.name is self then take the modules defined in the flake
|
|
||||||
# Otherwise its an external input which provides the modules via 'clan.modules' attribute
|
|
||||||
if moduleSpec.input == null then
|
|
||||||
localModuleSet
|
|
||||||
else
|
|
||||||
let
|
|
||||||
input =
|
|
||||||
flakeInputs.${moduleSpec.input} or (throw ''
|
|
||||||
Flake doesn't provide input with name '${moduleSpec.input}'
|
|
||||||
|
|
||||||
Choose one of the following inputs:
|
|
||||||
- ${
|
|
||||||
builtins.concatStringsSep "\n- " (
|
|
||||||
lib.attrNames (lib.filterAttrs (_name: input: input ? clan) flakeInputs)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
To import a local module from 'clan.modules' remove the 'input' attribute from the module definition
|
|
||||||
Remove the following line from the module definition:
|
|
||||||
|
|
||||||
...
|
|
||||||
- module.input = "${moduleSpec.input}"
|
|
||||||
|
|
||||||
'');
|
|
||||||
clanAttrs =
|
|
||||||
input.clan
|
|
||||||
or (throw "It seems the flake input ${moduleSpec.input} doesn't export any clan resources");
|
|
||||||
in
|
|
||||||
clanAttrs.modules;
|
|
||||||
|
|
||||||
resolvedModule =
|
|
||||||
resolvedModuleSet.${moduleSpec.name}
|
|
||||||
or (throw "flake doesn't provide clan-module with name ${moduleSpec.name}");
|
|
||||||
in
|
|
||||||
resolvedModule;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit evalClanService resolveModule;
|
|
||||||
mapInstances =
|
mapInstances =
|
||||||
{
|
{
|
||||||
# This is used to resolve the module imports from 'flake.inputs'
|
# This is used to resolve the module imports from 'flake.inputs'
|
||||||
@@ -151,7 +93,7 @@ in
|
|||||||
# 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:
|
||||||
evalClanService {
|
clanLib.evalService {
|
||||||
prefix = prefix ++ [ module_ident ];
|
prefix = prefix ++ [ module_ident ];
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
@@ -201,5 +143,4 @@ in
|
|||||||
importedModulesEvaluated
|
importedModulesEvaluated
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
lib/modules/inventory/distributed-service/resolveModule.nix
Normal file
43
lib/modules/inventory/distributed-service/resolveModule.nix
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{ lib }:
|
||||||
|
{
|
||||||
|
moduleSpec,
|
||||||
|
flakeInputs,
|
||||||
|
localModuleSet,
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
resolvedModuleSet =
|
||||||
|
# If the module.name is self then take the modules defined in the flake
|
||||||
|
# Otherwise its an external input which provides the modules via 'clan.modules' attribute
|
||||||
|
if moduleSpec.input == null then
|
||||||
|
localModuleSet
|
||||||
|
else
|
||||||
|
let
|
||||||
|
input =
|
||||||
|
flakeInputs.${moduleSpec.input} or (throw ''
|
||||||
|
Flake doesn't provide input with name '${moduleSpec.input}'
|
||||||
|
|
||||||
|
Choose one of the following inputs:
|
||||||
|
- ${
|
||||||
|
builtins.concatStringsSep "\n- " (
|
||||||
|
lib.attrNames (lib.filterAttrs (_name: input: input ? clan) flakeInputs)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
To import a local module from 'clan.modules' remove the 'input' attribute from the module definition
|
||||||
|
Remove the following line from the module definition:
|
||||||
|
|
||||||
|
...
|
||||||
|
- module.input = "${moduleSpec.input}"
|
||||||
|
|
||||||
|
'');
|
||||||
|
clanAttrs =
|
||||||
|
input.clan
|
||||||
|
or (throw "It seems the flake input ${moduleSpec.input} doesn't export any clan resources");
|
||||||
|
in
|
||||||
|
clanAttrs.modules;
|
||||||
|
|
||||||
|
resolvedModule =
|
||||||
|
resolvedModuleSet.${moduleSpec.name}
|
||||||
|
or (throw "flake doesn't provide clan-module with name ${moduleSpec.name}");
|
||||||
|
in
|
||||||
|
resolvedModule
|
||||||
@@ -82,13 +82,13 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
eval = clanLib.inventory.evalClanService {
|
eval = clanLib.evalService {
|
||||||
modules = [
|
modules = [
|
||||||
(consumer-A)
|
(consumer-A)
|
||||||
];
|
];
|
||||||
prefix = [ ];
|
prefix = [ ];
|
||||||
};
|
};
|
||||||
eval2 = clanLib.inventory.evalClanService {
|
eval2 = clanLib.evalService {
|
||||||
modules = [
|
modules = [
|
||||||
(consumer-B)
|
(consumer-B)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
eval = clanLib.inventory.evalClanService {
|
eval = clanLib.evalService {
|
||||||
modules = [
|
modules = [
|
||||||
(service-A)
|
(service-A)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
eval = clanLib.inventory.evalClanService {
|
eval = clanLib.evalService {
|
||||||
modules = [
|
modules = [
|
||||||
(service-A)
|
(service-A)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ in
|
|||||||
legacyPackages.clan-service-module-interface =
|
legacyPackages.clan-service-module-interface =
|
||||||
(pkgs.nixosOptionsDoc {
|
(pkgs.nixosOptionsDoc {
|
||||||
options =
|
options =
|
||||||
(self.clanLib.inventory.evalClanService {
|
(self.clanLib.evalService {
|
||||||
modules = [ ];
|
modules = [ ];
|
||||||
prefix = [ ];
|
prefix = [ ];
|
||||||
}).options;
|
}).options;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ let
|
|||||||
inspectModule =
|
inspectModule =
|
||||||
inputName: moduleName: module:
|
inputName: moduleName: module:
|
||||||
let
|
let
|
||||||
eval = clanLib.inventory.evalClanService {
|
eval = clanLib.evalService {
|
||||||
modules = [ module ];
|
modules = [ module ];
|
||||||
prefix = [
|
prefix = [
|
||||||
inputName
|
inputName
|
||||||
|
|||||||
Reference in New Issue
Block a user