Refactor(inventory/modules): add support for local clan.modules and migrate all checks

This commit is contained in:
Johannes Kirschbauer
2025-05-08 17:17:46 +02:00
parent 5b4a0a0311
commit b71e5378d6
7 changed files with 41 additions and 35 deletions

View File

@@ -34,33 +34,33 @@ clanLib.test.makeTestClan {
modules = {
legacy-module = ./legacy-module;
new-service = {
_class = "clan.service";
manifest.name = "new-service";
roles.peer = { };
perMachine = {
nixosModule = {
# This should be generated by:
# nix run .#generate-test-vars -- checks/dummy-inventory-test dummy-inventory-test
clan.core.vars.generators.new-service = {
files.not-a-secret = {
secret = false;
deploy = true;
};
files.a-secret = {
secret = true;
deploy = true;
owner = "nobody";
group = "users";
mode = "0644";
};
script = ''
# This is a dummy script that does nothing
echo -n "not-a-secret" > $out/not-a-secret
echo -n "a-secret" > $out/a-secret
'';
};
};
};
modules.new-service = {
_class = "clan.service";
manifest.name = "new-service";
roles.peer = { };
perMachine = {
nixosModule = {
# This should be generated by:
# nix run .#generate-test-vars -- checks/dummy-inventory-test dummy-inventory-test
clan.core.vars.generators.new-service = {
files.not-a-secret = {
secret = false;
deploy = true;
};
files.a-secret = {
secret = true;
deploy = true;
owner = "nobody";
group = "users";
mode = "0644";
};
script = ''
# This is a dummy script that does nothing
echo -n "not-a-secret" > $out/not-a-secret
echo -n "a-secret" > $out/a-secret
'';
};
};
};

View File

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

View File

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

View File

@@ -45,7 +45,8 @@ let
inherit inventory directory;
flakeInputs = config.self.inputs;
prefix = config._prefix ++ [ "inventoryClass" ];
localModuleSet = config.modules;
# TODO: remove inventory.modules, this is here for backwards compatibility
localModuleSet = inventory.modules // config.modules;
}
);

View File

@@ -33,6 +33,7 @@ let
distributedServices = clanLib.inventory.mapInstances {
inherit (config) inventory;
inherit localModuleSet;
inherit flakeInputs;
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:
...
@@ -81,6 +81,7 @@ in
flakeInputs,
# The clan inventory
inventory,
localModuleSet,
prefix ? [ ],
}:
let
@@ -92,7 +93,7 @@ in
let
resolvedModule = resolveModule {
moduleSpec = instance.module;
localModuleSet = inventory.modules;
inherit localModuleSet;
inherit flakeInputs;
};

View File

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