Merge pull request 'Refactor(inventory/modules): add support for local clan.modules and migrate all checks' (#3547) from hsjobeki/clan-core:clan-services into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3547
This commit is contained in:
hsjobeki
2025-05-08 15:50:26 +00:00
7 changed files with 42 additions and 35 deletions

View File

@@ -34,7 +34,9 @@ clanLib.test.makeTestClan {
modules = { modules = {
legacy-module = ./legacy-module; legacy-module = ./legacy-module;
new-service = { };
};
modules.new-service = {
_class = "clan.service"; _class = "clan.service";
manifest.name = "new-service"; manifest.name = "new-service";
roles.peer = { }; roles.peer = { };
@@ -64,8 +66,6 @@ clanLib.test.makeTestClan {
}; };
}; };
}; };
};
};
testScript = testScript =
{ nodes, ... }: { nodes, ... }:

View File

@@ -18,7 +18,7 @@ let
}; };
# Register the module for the test # Register the module for the test
inventory.modules.hello-world = module; modules.hello-world = module;
# Use the module in the test # Use the module in the test
inventory.instances = { inventory.instances = {

View File

@@ -14,6 +14,9 @@ clanLib.test.makeTestClan {
clan = { clan = {
directory = ./.; directory = ./.;
modules = {
hello-service = module;
};
inventory = { inventory = {
machines.peer1 = { }; machines.peer1 = { };
@@ -21,10 +24,6 @@ clanLib.test.makeTestClan {
module.name = "hello-service"; module.name = "hello-service";
roles.peer.machines.peer1 = { }; roles.peer.machines.peer1 = { };
}; };
modules = {
hello-service = module;
};
}; };
}; };

View File

@@ -45,7 +45,9 @@ let
inherit inventory directory; inherit inventory directory;
flakeInputs = config.self.inputs; flakeInputs = config.self.inputs;
prefix = config._prefix ++ [ "inventoryClass" ]; prefix = config._prefix ++ [ "inventoryClass" ];
localModuleSet = config.modules; # TODO: remove inventory.modules, this is here for backwards compatibility
localModuleSet =
lib.filterAttrs (n: _: !inventory._legacyModules ? ${n}) inventory.modules // config.modules;
} }
); );

View File

@@ -33,6 +33,7 @@ let
distributedServices = clanLib.inventory.mapInstances { distributedServices = clanLib.inventory.mapInstances {
inherit (config) inventory; inherit (config) inventory;
inherit localModuleSet;
inherit flakeInputs; inherit flakeInputs;
prefix = prefix ++ [ "distributedServices" ]; prefix = prefix ++ [ "distributedServices" ];
}; };

View File

@@ -54,7 +54,7 @@ let
) )
} }
To import a local module from 'inventory.modules' remove the 'input' attribute from the module definition To import a local module from 'clan.modules' remove the 'input' attribute from the module definition
Remove the following line from the module definition: Remove the following line from the module definition:
... ...
@@ -81,6 +81,7 @@ in
flakeInputs, flakeInputs,
# The clan inventory # The clan inventory
inventory, inventory,
localModuleSet,
prefix ? [ ], prefix ? [ ],
}: }:
let let
@@ -92,7 +93,7 @@ in
let let
resolvedModule = resolveModule { resolvedModule = resolveModule {
moduleSpec = instance.module; moduleSpec = instance.module;
localModuleSet = inventory.modules; inherit localModuleSet;
inherit flakeInputs; inherit flakeInputs;
}; };

View File

@@ -41,9 +41,13 @@ let
callInventoryAdapter = callInventoryAdapter =
inventoryModule: inventoryModule:
let
inventory = evalInventory inventoryModule;
in
clanLib.inventory.mapInstances { clanLib.inventory.mapInstances {
flakeInputs = flakeInputsFixture; flakeInputs = flakeInputsFixture;
inventory = evalInventory inventoryModule; inherit inventory;
localModuleSet = inventory.modules;
}; };
in in
{ {