Merge pull request 'clan services: use clan-core as a default source for services' (#4147) from davhau/dave into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4147
This commit is contained in:
DavHau
2025-06-30 10:13:46 +00:00
30 changed files with 83 additions and 42 deletions

View File

@@ -28,6 +28,7 @@ nixosLib.runTest (
borgone = {
module.name = "@clan/borgbackup";
module.input = "self";
roles.client.machines."clientone" = { };
roles.server.machines."serverone".settings.directory = "/tmp/borg-test";

View File

@@ -24,6 +24,7 @@
instances."test" = {
module.name = "new-service";
module.input = "self";
roles.peer.machines.peer1 = { };
};

View File

@@ -33,6 +33,7 @@ nixosLib.runTest (
instances."test" = {
module.name = "new-service";
module.input = "self";
roles.peer.machines.peer1 = { };
};

View File

@@ -26,6 +26,7 @@ nixosLib.runTest (
instances = {
mycelium-test = {
module.name = "@clan/mycelium";
module.input = "self";
roles.peer.machines."server".settings = {
openFirewall = true;
addHostedPublicNodes = true;

View File

@@ -14,6 +14,7 @@ in
instances = {
ssh-test-one = {
module.name = "@clan/admin";
module.input = "self";
roles.default.machines."server".settings = {
allowedKeys.testkey = public-key;
};

View File

@@ -18,6 +18,7 @@
borgone = {
module.name = "@clan/borgbackup";
module.input = "self";
roles.client.machines."clientone" = { };
roles.server.machines."serverone".settings.directory = "/tmp/borg-test";

View File

@@ -14,6 +14,7 @@
instances = {
garage-test = {
module.name = "@clan/garage";
module.input = "self";
roles.default.machines."server".settings = { };
};
};

View File

@@ -24,6 +24,7 @@ let
inventory.instances = {
"hello" = {
module.name = "hello-world";
module.input = "self";
roles.peer.machines.jon = { };
};

View File

@@ -12,6 +12,7 @@
instances."test" = {
module.name = "hello-service";
module.input = "self";
roles.peer.machines.peer1 = { };
};
};

View File

@@ -16,6 +16,7 @@
instances = {
mycelium-test = {
module.name = "@clan/mycelium";
module.input = "self";
roles.peer.machines."server".settings = {
openFirewall = true;
addHostedPublicNodes = true;

View File

@@ -1,7 +1,3 @@
{
module,
...
}:
{
name = "packages";
@@ -12,6 +8,7 @@
instances.default = {
module.name = "@clan/packages";
module.input = "self";
roles.default.machines."server".settings = {
packages = [ "cbonsai" ];
};

View File

@@ -15,6 +15,7 @@
instances = {
sshd-test = {
module.name = "@clan/sshd";
module.input = "self";
roles.server.machines."server".settings = {
certificate.searchDomains = [ "example.com" ];
hostKeys.rsa.enable = true;

View File

@@ -7,6 +7,7 @@
machines.server = { };
instances.default = {
module.name = "@clan/state-version";
module.input = "self";
roles.default.machines."server" = { };
};
};

View File

@@ -9,6 +9,7 @@
instances = {
trusted-nix-caches = {
module.name = "@clan/trusted-nix-caches";
module.input = "self";
roles.default.machines."server" = { };
};
};

View File

@@ -9,6 +9,7 @@
instances = {
root-password-test = {
module.name = "@clan/users";
module.input = "self";
roles.default.machines."server".settings = {
user = "root";
prompt = false;
@@ -16,6 +17,7 @@
};
user-password-test = {
module.name = "@clan/users";
module.input = "self";
roles.default.machines."server".settings = {
user = "testuser";
prompt = false;

View File

@@ -24,6 +24,7 @@ let
inventory.instances = {
"default" = {
module.name = "wifi";
module.input = "self";
roles.default.tags.all = { };
roles.default.settings.networks.one = { };
roles.default.settings.networks.two = { };

View File

@@ -11,6 +11,7 @@
instances = {
wg-test-one = {
module.name = "@clan/wifi";
module.input = "self";
roles.default.machines = {
test.settings.networks.one = { };

View File

@@ -22,6 +22,7 @@ let
inventory.instances = {
zerotier = {
module.name = "zerotier";
module.input = "self";
roles.peer.tags.all = { };
roles.moon.machines.sara.settings.stableEndpoints = [ "10.0.0.3/9993" ];

View File

@@ -12,6 +12,7 @@
instances = {
"zerotier" = {
module.name = "zerotier";
module.input = "self";
roles.peer.tags.all = { };
roles.controller.machines.bam = { };

View File

@@ -205,9 +205,6 @@ in
nixpkgs
nix-darwin
;
# By default clan.directory defaults to self, but we don't
# have a sensible default for self here
self = throw "set clan.directory in the test";
};
modules = [
clan-core.modules.clan.default

View File

@@ -31,7 +31,7 @@ lib.fix (
# ------------------------------------
# ClanLib functions
evalClan = clanLib.callLib ./modules/inventory/eval-clan-modules { };
inventory = clanLib.callLib ./modules/inventory { };
inventory = clanLib.callLib ./modules/inventory { clan-core = self; };
modules = clanLib.callLib ./modules/inventory/frontmatter { };
test = clanLib.callLib ./test { };
# Custom types

View File

@@ -238,7 +238,7 @@ in
imports = [
../inventoryClass/builder/default.nix
(lib.modules.importApply ../inventoryClass/service-list-from-inputs.nix {
inherit localModuleSet flakeInputs clanLib;
inherit flakeInputs clanLib localModuleSet;
})
{
inherit inventory directory;

View File

@@ -1,6 +1,12 @@
{ lib, clanLib }:
{
lib,
clanLib,
clan-core,
}:
let
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
services = clanLib.callLib ./distributed-service/inventory-adapter.nix {
inherit clan-core;
};
in
{
inherit (services) mapInstances;

View File

@@ -12,10 +12,11 @@
{
lib,
clanLib,
clan-core,
...
}:
let
resolveModule = import ./resolveModule.nix { inherit lib; };
resolveModule = import ./resolveModule.nix { inherit lib clan-core; };
in
{
mapInstances =

View File

@@ -1,19 +1,12 @@
{ lib }:
{ lib, clan-core }:
{
moduleSpec,
flakeInputs,
localModuleSet,
}:
let
resolvedModuleSet =
# If the module.name is self then take the modules defined in the flake
# Otherwise its an external input which provides the modules via 'clan.modules' attribute
if moduleSpec.input == null then
localModuleSet
else
let
input =
flakeInputs.${moduleSpec.input} or (throw ''
inputName = if moduleSpec.input == null then "<clan>" else moduleSpec.input;
inputError = throw ''
Flake doesn't provide input with name '${moduleSpec.input}'
Choose one of the following inputs:
@@ -29,15 +22,24 @@ let
...
- module.input = "${moduleSpec.input}"
'');
clanAttrs =
input.clan
or (throw "It seems the flake input ${moduleSpec.input} doesn't export any clan resources");
'';
resolvedModuleSet =
# If the module.name is self then take the modules defined in the flake
# Otherwise its an external input which provides the modules via 'clan.modules' attribute
let
input =
if moduleSpec.input == null then
clan-core
else if moduleSpec.input == "self" then
{ clan.modules = localModuleSet; }
else
flakeInputs.${moduleSpec.input} or inputError;
in
clanAttrs.modules;
input.clan.modules
or (throw "flake input ${moduleSpec.input} doesn't export any clan services via the `clan.modules` output attribute");
resolvedModule =
resolvedModuleSet.${moduleSpec.name}
or (throw "flake doesn't provide clan-module with name ${moduleSpec.name}");
or (throw "flake input '${inputName}' doesn't provide clan-module with name ${moduleSpec.name}");
in
resolvedModule

View File

@@ -151,16 +151,19 @@ in
instances."instance_foo" = {
module = {
name = "A";
input = "self";
};
};
instances."instance_bar" = {
module = {
name = "A";
input = "self";
};
};
instances."instance_zaza" = {
module = {
name = "B";
input = "self";
};
};
};
@@ -186,6 +189,7 @@ in
_class = "clan.service";
manifest = {
name = "network";
input = "self";
};
# Define a role without special behavior
roles.peer = { };
@@ -200,18 +204,21 @@ in
instances."instance_foo" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.jon = { };
};
instances."instance_bar" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.sara = { };
};
instances."instance_zaza" = {
module = {
name = "B";
input = "self";
};
roles.peer.tags.all = { };
};
@@ -256,12 +263,14 @@ in
instances."instance_foo" = {
module = {
name = "A";
input = "self";
};
roles.peer.tags.foo = { };
};
instances."instance_zaza" = {
module = {
name = "B";
input = "self";
};
roles.peer.tags.all = { };
};

View File

@@ -32,7 +32,11 @@ let
in
{
test_import_local_module_by_name = {
expr = (resolve { name = "A"; }).importedModuleWithInstances.instance_foo.resolvedModule;
expr =
(resolve {
name = "A";
input = "self";
}).importedModuleWithInstances.instance_foo.resolvedModule;
expected = {
_class = "clan.service";
manifest = {

View File

@@ -62,6 +62,7 @@ let
instances."instance_foo" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.jon = {
settings.timeout = lib.mkForce "foo-peer-jon";
@@ -74,6 +75,7 @@ let
instances."instance_bar" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.jon = {
settings.timeout = "bar-peer-jon";

View File

@@ -44,6 +44,7 @@ let
instances."instance_foo" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.jon = {
settings.timeout = lib.mkForce "foo-peer-jon";
@@ -55,6 +56,7 @@ let
instances."instance_bar" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.jon = {
settings.timeout = "bar-peer-jon";
@@ -63,6 +65,7 @@ let
instances."instance_zaza" = {
module = {
name = "B";
input = "self";
};
roles.peer.tags.all = { };
};

View File

@@ -17,6 +17,7 @@
machines.server = { };
instances.importer = {
module.name = "@clan/importer";
module.input = "self";
roles.default.tags.all = { };
roles.default.extraModules = [
{