API(clanInternals): add 'evalServiceSchema' endpoint
This commit is contained in:
@@ -174,6 +174,7 @@ in
|
|||||||
inventoryFile = lib.mkOption { type = lib.types.raw; };
|
inventoryFile = lib.mkOption { type = lib.types.raw; };
|
||||||
# The machine 'imports' generated by the inventory per machine
|
# The machine 'imports' generated by the inventory per machine
|
||||||
inventoryClass = lib.mkOption { type = lib.types.raw; };
|
inventoryClass = lib.mkOption { type = lib.types.raw; };
|
||||||
|
evalServiceSchema = lib.mkOption { };
|
||||||
# clan-core's modules
|
# clan-core's modules
|
||||||
clanModules = lib.mkOption { type = lib.types.raw; };
|
clanModules = lib.mkOption { type = lib.types.raw; };
|
||||||
source = lib.mkOption { type = lib.types.raw; };
|
source = lib.mkOption { type = lib.types.raw; };
|
||||||
|
|||||||
@@ -205,6 +205,21 @@ in
|
|||||||
|
|
||||||
inherit inventoryClass;
|
inherit inventoryClass;
|
||||||
|
|
||||||
|
# Endpoint that can be called to get a service schema
|
||||||
|
evalServiceSchema =
|
||||||
|
{moduleSpec}:
|
||||||
|
let
|
||||||
|
resolvedModule = clan-core.clanLib.inventory.resolveModule {
|
||||||
|
inherit moduleSpec;
|
||||||
|
flakeInputs = config.self.inputs;
|
||||||
|
localModuleSet = config.inventory.modules;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
(clan-core.clanLib.inventory.evalClanService {
|
||||||
|
modules = [ resolvedModule ];
|
||||||
|
prefix = [ ];
|
||||||
|
}).config.result.api.schema;
|
||||||
|
|
||||||
# TODO: unify this interface
|
# TODO: unify this interface
|
||||||
# We should have only clan.modules. (consistent with clan.templates)
|
# We should have only clan.modules. (consistent with clan.templates)
|
||||||
inherit (clan-core) clanModules clanLib;
|
inherit (clan-core) clanModules clanLib;
|
||||||
|
|||||||
@@ -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;
|
inherit (services) evalClanService mapInstances resolveModule;
|
||||||
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;
|
||||||
# Returns the list of machine names
|
# Returns the list of machine names
|
||||||
|
|||||||
@@ -27,9 +27,53 @@ let
|
|||||||
})
|
})
|
||||||
] ++ modules;
|
] ++ 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 'inventory.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;
|
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'
|
||||||
@@ -45,42 +89,11 @@ in
|
|||||||
importedModuleWithInstances = lib.mapAttrs (
|
importedModuleWithInstances = lib.mapAttrs (
|
||||||
instanceName: instance:
|
instanceName: instance:
|
||||||
let
|
let
|
||||||
# TODO:
|
resolvedModule = resolveModule {
|
||||||
resolvedModuleSet =
|
moduleSpec = instance.module;
|
||||||
# If the module.name is self then take the modules defined in the flake
|
localModuleSet = inventory.modules;
|
||||||
# Otherwise its an external input which provides the modules via 'clan.modules' attribute
|
inherit flakeInputs;
|
||||||
if instance.module.input == null then
|
};
|
||||||
inventory.modules
|
|
||||||
else
|
|
||||||
let
|
|
||||||
input =
|
|
||||||
flakeInputs.${instance.module.input} or (throw ''
|
|
||||||
Flake doesn't provide input with name '${instance.module.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 'inventory.modules' remove the 'input' attribute from the module definition
|
|
||||||
Remove the following line from the module definition:
|
|
||||||
|
|
||||||
...
|
|
||||||
- module.input = "${instance.module.input}"
|
|
||||||
|
|
||||||
|
|
||||||
'');
|
|
||||||
clanAttrs =
|
|
||||||
input.clan
|
|
||||||
or (throw "It seems the flake input ${instance.module.input} doesn't export any clan resources");
|
|
||||||
in
|
|
||||||
clanAttrs.modules;
|
|
||||||
|
|
||||||
resolvedModule =
|
|
||||||
resolvedModuleSet.${instance.module.name}
|
|
||||||
or (throw "flake doesn't provide clan-module with name ${instance.module.name}");
|
|
||||||
|
|
||||||
# Every instance includes machines via roles
|
# Every instance includes machines via roles
|
||||||
# :: { client :: ... }
|
# :: { client :: ... }
|
||||||
|
|||||||
Reference in New Issue
Block a user