Remove clanModules

This commit is contained in:
pinpox
2025-07-04 15:54:44 +02:00
parent c49a7c8277
commit 546eeb22d0
136 changed files with 40 additions and 5488 deletions

View File

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

View File

@@ -88,6 +88,7 @@ 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 = "self";
input = null;
};
roles.peer.tags.all = { };
};

View File

@@ -121,45 +121,7 @@ let
);
checkConstraints = args: (evalFrontmatter args).config.constraints.assertions;
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...
'';
getFrontmatter = _modulepath: _modulename: "clanModules are removed!";
in
{
inherit

View File

@@ -62,135 +62,6 @@ 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
@@ -216,84 +87,4 @@ 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,27 +161,7 @@ in
```
'';
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;
apply = _: { };
};
assertions = lib.mkOption {