revert Merge pull request 'Remove clanModules/*' (#4202) from remove-modules into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4202

See: https://git.clan.lol/clan/clan-core/issues/4365

Not all modules are migrated.
If they are not migrated, we need to write migration docs and please display the link to the migration docs
This commit is contained in:
hsjobeki
2025-07-15 17:51:36 +00:00
parent 9bb366cdd7
commit 341f444fa0
136 changed files with 5488 additions and 40 deletions

View File

@@ -32,7 +32,7 @@ let
let
inventory = evalInventory inventoryModule;
flakeInputsFixture = {
self.clan.modules = inventoryModule.modules or { };
self.clan.modules = inventory.modules;
# Example upstream module
upstream.clan.modules = {
uzzi = {
@@ -165,7 +165,7 @@ in
instances."instance_zaza" = {
module = {
name = "B";
input = null;
input = "self";
};
};
};
@@ -191,7 +191,7 @@ in
_class = "clan.service";
manifest = {
name = "network";
input = null;
input = "self";
};
# Define a role without special behavior
roles.peer = { };
@@ -220,7 +220,7 @@ in
instances."instance_zaza" = {
module = {
name = "B";
input = null;
input = "self";
};
roles.peer.tags.all = { };
};
@@ -272,7 +272,7 @@ in
instances."instance_zaza" = {
module = {
name = "B";
input = null;
input = "self";
};
roles.peer.tags.all = { };
};

View File

@@ -88,7 +88,6 @@ let
instances."instance_zaza" = {
module = {
name = "B";
input = null;
};
roles.peer.tags.all = { };
};

View File

@@ -65,7 +65,7 @@ let
instances."instance_zaza" = {
module = {
name = "B";
input = null;
input = "self";
};
roles.peer.tags.all = { };
};

View File

@@ -121,7 +121,45 @@ let
);
checkConstraints = args: (evalFrontmatter args).config.constraints.assertions;
getFrontmatter = _modulepath: _modulename: "clanModules are removed!";
getReadme =
modulepath: modulename:
let
readme = modulepath + "/README.md";
readmeContents =
if (builtins.pathExists readme) then
(builtins.readFile readme)
else
throw "No README.md found for module ${modulename} (expected at ${readme})";
in
readmeContents;
getFrontmatter =
modulepath: modulename:
let
content = getReadme modulepath modulename;
parts = lib.splitString "---" content;
# Partition the parts into the first part (the readme content) and the rest (the metadata)
parsed = builtins.partition ({ index, ... }: if index >= 2 then false else true) (
lib.filter ({ index, ... }: index != 0) (lib.imap0 (index: part: { inherit index part; }) parts)
);
meta = builtins.fromTOML (builtins.head parsed.right).part;
in
if (builtins.length parts >= 3) then
meta
else
throw ''
TOML Frontmatter not found in README.md for module ${modulename}
Please add the following to the top of your README.md:
---
description = "Your description here"
categories = [ "Your categories here" ]
features = [ "inventory" ]
---
...rest of your README.md...
'';
in
{
inherit

View File

@@ -62,6 +62,135 @@ in
expr = eval.config.clanInternals.inventoryClass.machines;
expected = { };
};
test_inventory_role_resolve =
let
eval = clan {
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.server.machines = [ "backup_server" ];
roles.client.machines = [
"client_1_machine"
"client_2_machine"
];
};
};
machines = {
"backup_server" = { };
"client_1_machine" = { };
"client_2_machine" = { };
};
};
};
in
{
expr = {
m1 =
(eval.config.clanInternals.inventoryClass.machines."backup_server")
.compiledServices.borgbackup.matchedRoles;
m2 =
(eval.config.clanInternals.inventoryClass.machines."client_1_machine")
.compiledServices.borgbackup.matchedRoles;
m3 =
(eval.config.clanInternals.inventoryClass.machines."client_2_machine")
.compiledServices.borgbackup.matchedRoles;
inherit
((eval.config.clanInternals.inventoryClass.machines."client_2_machine").compiledServices.borgbackup)
resolvedRolesPerInstance
;
};
expected = {
m1 = [
"server"
];
m2 = [
"client"
];
m3 = [
"client"
];
resolvedRolesPerInstance = {
instance_1 = {
client = {
machines = [
"client_1_machine"
"client_2_machine"
];
};
server = {
machines = [ "backup_server" ];
};
};
};
};
};
test_inventory_tag_resolve =
let
eval = clan {
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.client.tags = [ "backup" ];
};
};
machines = {
"not_used_machine" = { };
"client_1_machine" = {
tags = [ "backup" ];
};
"client_2_machine" = {
tags = [ "backup" ];
};
};
};
};
in
{
expr =
eval.config.clanInternals.inventoryClass.machines.client_1_machine.compiledServices.borgbackup.resolvedRolesPerInstance;
expected = {
instance_1 = {
client = {
machines = [
"client_1_machine"
"client_2_machine"
];
};
server = {
machines = [ ];
};
};
};
};
test_inventory_multiple_roles =
let
eval = clan {
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ];
roles.server.machines = [ "machine_1" ];
};
};
machines = {
"machine_1" = { };
};
};
};
in
{
expr =
eval.config.clanInternals.inventoryClass.machines.machine_1.compiledServices.borgbackup.matchedRoles;
expected = [
"client"
"server"
];
};
test_inventory_module_doesnt_exist =
let
@@ -87,4 +216,84 @@ in
msg = "ClanModule not found*";
};
};
test_inventory_role_doesnt_exist =
let
eval = clan {
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.roleXYZ.machines = [ "machine_1" ];
};
};
machines = {
"machine_1" = { };
};
};
};
in
{
inherit eval;
expr = eval.config.clanInternals.inventoryClass.machines.machine_1.machineImports;
expectedError = {
type = "ThrownError";
msg = ''Roles \["roleXYZ"\] are not defined in the service borgbackup'';
};
};
# Needs NIX_ABORT_ON_WARN=1
# So the lib.warn is turned into abort
test_inventory_tag_doesnt_exist =
let
eval = clan {
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ];
roles.client.tags = [ "tagXYZ" ];
};
};
machines = {
"machine_1" = {
tags = [ "tagABC" ];
};
};
};
};
in
{
expr = eval.config.clanInternals.inventoryClass.machines.machine_1.machineImports;
expectedError = {
type = "Error";
# TODO: Add warning matching in nix-unit
msg = ".*";
};
};
test_inventory_disabled_service =
let
eval = clan {
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
enabled = false;
roles.client.machines = [ "machine_1" ];
};
};
machines = {
"machine_1" = {
};
};
};
};
in
{
inherit eval;
expr = builtins.filter (
v: v != { } && !v.clan.inventory.assertions ? "alive.assertion.inventory"
) eval.config.clanInternals.inventoryClass.machines.machine_1.machineImports;
expected = [ ];
};
}

View File

@@ -161,7 +161,27 @@ in
```
'';
apply = _: { };
apply =
moduleSet:
let
allowedNames = lib.attrNames config._legacyModules;
in
if builtins.all (moduleName: builtins.elem moduleName allowedNames) (lib.attrNames moduleSet) then
moduleSet
else
lib.warn ''
`inventory.modules` will be deprecated soon.
Please migrate the following modules into `clan.service` modules
and register them in `clan.modules`
${lib.concatStringsSep "\n" (
map (m: "'${m}'") (lib.attrNames (lib.filterAttrs (n: _v: !builtins.elem n allowedNames) moduleSet))
)}
See: https://docs.clan.lol/guides/clanServices/
And: https://docs.clan.lol/guides/authoring/clanServices/
'' moduleSet;
};
assertions = lib.mkOption {