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:
@@ -34,33 +34,33 @@ clanLib.test.makeTestClan {
|
|||||||
|
|
||||||
modules = {
|
modules = {
|
||||||
legacy-module = ./legacy-module;
|
legacy-module = ./legacy-module;
|
||||||
new-service = {
|
};
|
||||||
_class = "clan.service";
|
};
|
||||||
manifest.name = "new-service";
|
modules.new-service = {
|
||||||
roles.peer = { };
|
_class = "clan.service";
|
||||||
perMachine = {
|
manifest.name = "new-service";
|
||||||
nixosModule = {
|
roles.peer = { };
|
||||||
# This should be generated by:
|
perMachine = {
|
||||||
# nix run .#generate-test-vars -- checks/dummy-inventory-test dummy-inventory-test
|
nixosModule = {
|
||||||
clan.core.vars.generators.new-service = {
|
# This should be generated by:
|
||||||
files.not-a-secret = {
|
# nix run .#generate-test-vars -- checks/dummy-inventory-test dummy-inventory-test
|
||||||
secret = false;
|
clan.core.vars.generators.new-service = {
|
||||||
deploy = true;
|
files.not-a-secret = {
|
||||||
};
|
secret = false;
|
||||||
files.a-secret = {
|
deploy = true;
|
||||||
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
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
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
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 = {
|
||||||
|
|||||||
@@ -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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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" ];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user