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:
@@ -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";
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
instances."test" = {
|
||||
module.name = "new-service";
|
||||
module.input = "self";
|
||||
roles.peer.machines.peer1 = { };
|
||||
};
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ nixosLib.runTest (
|
||||
|
||||
instances."test" = {
|
||||
module.name = "new-service";
|
||||
module.input = "self";
|
||||
roles.peer.machines.peer1 = { };
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
instances = {
|
||||
garage-test = {
|
||||
module.name = "@clan/garage";
|
||||
module.input = "self";
|
||||
roles.default.machines."server".settings = { };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@ let
|
||||
inventory.instances = {
|
||||
"hello" = {
|
||||
module.name = "hello-world";
|
||||
module.input = "self";
|
||||
|
||||
roles.peer.machines.jon = { };
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
instances."test" = {
|
||||
module.name = "hello-service";
|
||||
module.input = "self";
|
||||
roles.peer.machines.peer1 = { };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
instances = {
|
||||
mycelium-test = {
|
||||
module.name = "@clan/mycelium";
|
||||
module.input = "self";
|
||||
roles.peer.machines."server".settings = {
|
||||
openFirewall = true;
|
||||
addHostedPublicNodes = true;
|
||||
|
||||
@@ -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" ];
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
machines.server = { };
|
||||
instances.default = {
|
||||
module.name = "@clan/state-version";
|
||||
module.input = "self";
|
||||
roles.default.machines."server" = { };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
instances = {
|
||||
trusted-nix-caches = {
|
||||
module.name = "@clan/trusted-nix-caches";
|
||||
module.input = "self";
|
||||
roles.default.machines."server" = { };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = { };
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
instances = {
|
||||
wg-test-one = {
|
||||
module.name = "@clan/wifi";
|
||||
module.input = "self";
|
||||
|
||||
roles.default.machines = {
|
||||
test.settings.networks.one = { };
|
||||
|
||||
@@ -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" ];
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
instances = {
|
||||
"zerotier" = {
|
||||
module.name = "zerotier";
|
||||
module.input = "self";
|
||||
|
||||
roles.peer.tags.all = { };
|
||||
roles.controller.machines.bam = { };
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = { };
|
||||
};
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 = { };
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
machines.server = { };
|
||||
instances.importer = {
|
||||
module.name = "@clan/importer";
|
||||
module.input = "self";
|
||||
roles.default.tags.all = { };
|
||||
roles.default.extraModules = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user