Compare commits
28 Commits
push-qxwmr
...
push-pmmln
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97f5ffd813 | ||
|
|
196b98da36 | ||
|
|
42acbe95b8 | ||
|
|
b6b065e365 | ||
|
|
4b1955b189 | ||
|
|
ef7ef8b843 | ||
|
|
38c1367322 | ||
|
|
8e72c086fd | ||
|
|
c454b1339d | ||
|
|
d1b2d43e5b | ||
|
|
da98ca0f1c | ||
|
|
1953540d08 | ||
|
|
be31b9ce21 | ||
|
|
169b4016e6 | ||
|
|
2e55028a1b | ||
|
|
1d228231f2 | ||
|
|
affb926450 | ||
|
|
c7f65e929f | ||
|
|
ba4ff493e8 | ||
|
|
eb08803e2a | ||
|
|
bbc9486f0e | ||
|
|
999d709350 | ||
|
|
0b1a330cc2 | ||
|
|
995b7cf50d | ||
|
|
5477b13233 | ||
|
|
d6170e5efb | ||
|
|
18fe117363 | ||
|
|
33a868acc2 |
@@ -39,6 +39,7 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
|
||||||
# Collect searchDomains from all servers in this instance
|
# Collect searchDomains from all servers in this instance
|
||||||
allServerSearchDomains = lib.flatten (
|
allServerSearchDomains = lib.flatten (
|
||||||
lib.mapAttrsToList (_name: machineConfig: machineConfig.settings.certificate.searchDomains or [ ]) (
|
lib.mapAttrsToList (_name: machineConfig: machineConfig.settings.certificate.searchDomains or [ ]) (
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
# Merge client's searchDomains with all servers' searchDomains
|
# Merge client's searchDomains with all servers' searchDomains
|
||||||
searchDomains = lib.uniqueStrings (settings.certificate.searchDomains ++ allServerSearchDomains);
|
searchDomains = uniqueStrings (settings.certificate.searchDomains ++ allServerSearchDomains);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
clan.core.vars.generators.openssh-ca = lib.mkIf (searchDomains != [ ]) {
|
clan.core.vars.generators.openssh-ca = lib.mkIf (searchDomains != [ ]) {
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ let
|
|||||||
# In this case it is 'self-zerotier-redux'
|
# In this case it is 'self-zerotier-redux'
|
||||||
# This is usually only used internally, but we can use it to test the evaluation of service module in isolation
|
# This is usually only used internally, but we can use it to test the evaluation of service module in isolation
|
||||||
# evaluatedService =
|
# evaluatedService =
|
||||||
# testFlake.clanInternals.inventoryClass.distributedServices.importedModulesEvaluated.self-zerotier-redux.config;
|
# testFlake.clanInternals.inventoryClass.distributedServices.servicesEval.config.mappedServices.self-zerotier-redux.config;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_simple = {
|
test_simple = {
|
||||||
inherit testFlake;
|
inherit testFlake;
|
||||||
|
|
||||||
expr =
|
expr =
|
||||||
testFlake.config.clan.clanInternals.inventoryClass.distributedServices.importedModulesEvaluated.self-wifi.config;
|
testFlake.config.clan.clanInternals.inventoryClass.distributedServices.servicesEval.config.mappedServices.self-wifi.config;
|
||||||
expected = 1;
|
expected = 1;
|
||||||
|
|
||||||
# expr = {
|
# expr = {
|
||||||
|
|||||||
@@ -56,6 +56,8 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
clanLib,
|
clanLib,
|
||||||
|
lib,
|
||||||
|
directory,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@@ -298,6 +300,18 @@ in
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
|
exports.networking = {
|
||||||
|
peers = lib.mapAttrs (name: _machine: {
|
||||||
|
host.plain =
|
||||||
|
clanLib.vars.getPublicValue {
|
||||||
|
flake = directory;
|
||||||
|
machine = name;
|
||||||
|
generator = "wireguard-network-${instanceName}";
|
||||||
|
file = "prefix";
|
||||||
|
}
|
||||||
|
+ "::1";
|
||||||
|
}) roles.controller.machines;
|
||||||
|
};
|
||||||
|
|
||||||
# Controllers connect to all peers and other controllers
|
# Controllers connect to all peers and other controllers
|
||||||
nixosModule =
|
nixosModule =
|
||||||
|
|||||||
@@ -140,6 +140,9 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
|
||||||
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(import ./shared.nix {
|
(import ./shared.nix {
|
||||||
@@ -156,7 +159,7 @@
|
|||||||
config = {
|
config = {
|
||||||
systemd.services.zerotier-inventory-autoaccept =
|
systemd.services.zerotier-inventory-autoaccept =
|
||||||
let
|
let
|
||||||
machines = lib.uniqueStrings (
|
machines = uniqueStrings (
|
||||||
(lib.optionals (roles ? moon) (lib.attrNames roles.moon.machines))
|
(lib.optionals (roles ? moon) (lib.attrNames roles.moon.machines))
|
||||||
++ (lib.optionals (roles ? controller) (lib.attrNames roles.controller.machines))
|
++ (lib.optionals (roles ? controller) (lib.attrNames roles.controller.machines))
|
||||||
++ (lib.optionals (roles ? peer) (lib.attrNames roles.peer.machines))
|
++ (lib.optionals (roles ? peer) (lib.attrNames roles.peer.machines))
|
||||||
|
|||||||
12
devFlake/flake.lock
generated
12
devFlake/flake.lock
generated
@@ -105,11 +105,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-dev": {
|
"nixpkgs-dev": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1761631514,
|
"lastModified": 1761853358,
|
||||||
"narHash": "sha256-VsXz+2W4DFBozzppbF9SXD9pNcv17Z+c/lYXvPJi/eI=",
|
"narHash": "sha256-1tBdsBzYJOzVzNOmCFzFMWHw7UUbhkhiYCFGr+OjPTs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "a0b0d4b52b5f375658ca8371dc49bff171dbda91",
|
"rev": "262333bca9b49964f8e3cad3af655466597c01d4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -128,11 +128,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760652422,
|
"lastModified": 1761730856,
|
||||||
"narHash": "sha256-C88Pgz38QIl9JxQceexqL2G7sw9vodHWx1Uaq+NRJrw=",
|
"narHash": "sha256-t1i5p/vSWwueZSC0Z2BImxx3BjoUDNKyC2mk24krcMY=",
|
||||||
"owner": "NuschtOS",
|
"owner": "NuschtOS",
|
||||||
"repo": "search",
|
"repo": "search",
|
||||||
"rev": "3ebeebe8b6a49dfb11f771f761e0310f7c48d726",
|
"rev": "e29de6db0cb3182e9aee75a3b1fd1919d995d85b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
6
flake.lock
generated
6
flake.lock
generated
@@ -31,11 +31,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1760701190,
|
"lastModified": 1761899396,
|
||||||
"narHash": "sha256-y7UhnWlER8r776JsySqsbTUh2Txf7K30smfHlqdaIQw=",
|
"narHash": "sha256-XOpKBp6HLzzMCbzW50TEuXN35zN5WGQREC7n34DcNMM=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "disko",
|
"repo": "disko",
|
||||||
"rev": "3a9450b26e69dcb6f8de6e2b07b3fc1c288d85f5",
|
"rev": "6f4cf5abbe318e4cd1e879506f6eeafd83f7b998",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -2,11 +2,7 @@
|
|||||||
lib,
|
lib,
|
||||||
clanLib,
|
clanLib,
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
services = clanLib.callLib ./distributed-service/inventory-adapter.nix { };
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
inherit (services) mapInstances;
|
|
||||||
inventoryModule = {
|
inventoryModule = {
|
||||||
_file = "clanLib.inventory.module";
|
_file = "clanLib.inventory.module";
|
||||||
imports = [
|
imports = [
|
||||||
|
|||||||
@@ -28,19 +28,15 @@ in
|
|||||||
elemType = submoduleWith {
|
elemType = submoduleWith {
|
||||||
class = "clan.service";
|
class = "clan.service";
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
exports = config.exports;
|
|
||||||
directory = directory;
|
directory = directory;
|
||||||
clanLib = specialArgs.clanLib;
|
clanLib = specialArgs.clanLib;
|
||||||
|
exports = config.exports;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
(
|
(
|
||||||
{ name, ... }:
|
{ name, ... }:
|
||||||
{
|
{
|
||||||
_module.args._ctx = [ name ];
|
_module.args._ctx = [ name ];
|
||||||
_module.args.clanLib = specialArgs.clanLib;
|
|
||||||
_module.args.exports = config.exports;
|
|
||||||
_module.args.directory = directory;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
./service-module.nix
|
./service-module.nix
|
||||||
|
|||||||
@@ -1,171 +0,0 @@
|
|||||||
# Adapter function between the inventory.instances and the clan.service module
|
|
||||||
#
|
|
||||||
# Data flow:
|
|
||||||
# - inventory.instances -> Adapter -> clan.service module -> Service Resources (i.e. NixosModules per Machine, Vars per Service, etc.)
|
|
||||||
#
|
|
||||||
# What this file does:
|
|
||||||
#
|
|
||||||
# - Resolves the [Module] to an actual module-path and imports it.
|
|
||||||
# - Groups together all the same modules into a single import and creates all instances for it.
|
|
||||||
# - Resolves the inventory tags into machines. Tags don't exist at the service level.
|
|
||||||
# Also combines the settings for 'machines' and 'tags'.
|
|
||||||
{
|
|
||||||
lib,
|
|
||||||
clanLib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
mapInstances =
|
|
||||||
{
|
|
||||||
# This is used to resolve the module imports from 'flake.inputs'
|
|
||||||
flakeInputs,
|
|
||||||
# The clan inventory
|
|
||||||
inventory,
|
|
||||||
directory,
|
|
||||||
clanCoreModules,
|
|
||||||
prefix ? [ ],
|
|
||||||
exportsModule,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
# machineHasTag = machineName: tagName: lib.elem tagName inventory.machines.${machineName}.tags;
|
|
||||||
|
|
||||||
# map the instances into the module
|
|
||||||
importedModuleWithInstances = lib.mapAttrs (
|
|
||||||
instanceName: instance:
|
|
||||||
let
|
|
||||||
resolvedModule = clanLib.resolveModule {
|
|
||||||
moduleSpec = instance.module;
|
|
||||||
inherit flakeInputs clanCoreModules;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Every instance includes machines via roles
|
|
||||||
# :: { client :: ... }
|
|
||||||
instanceRoles = lib.mapAttrs (
|
|
||||||
roleName: role:
|
|
||||||
let
|
|
||||||
resolvedMachines = clanLib.inventory.resolveTags {
|
|
||||||
members = {
|
|
||||||
# Explicit members
|
|
||||||
machines = lib.attrNames role.machines;
|
|
||||||
# Resolved Members
|
|
||||||
tags = lib.attrNames role.tags;
|
|
||||||
};
|
|
||||||
inherit (inventory) machines;
|
|
||||||
inherit instanceName roleName;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
# instances.<instanceName>.roles.<roleName> =
|
|
||||||
# Remove "tags", they are resolved into "machines"
|
|
||||||
(removeAttrs role [ "tags" ])
|
|
||||||
// {
|
|
||||||
machines = lib.genAttrs resolvedMachines.machines (
|
|
||||||
machineName:
|
|
||||||
let
|
|
||||||
machineSettings = instance.roles.${roleName}.machines.${machineName}.settings or { };
|
|
||||||
in
|
|
||||||
# TODO: tag settings
|
|
||||||
# Wait for this feature until option introspection for 'settings' is done.
|
|
||||||
# This might get too complex to handle otherwise.
|
|
||||||
# settingsViaTags = lib.filterAttrs (
|
|
||||||
# tagName: _: machineHasTag machineName tagName
|
|
||||||
# ) instance.roles.${roleName}.tags;
|
|
||||||
{
|
|
||||||
# TODO: Do we want to wrap settings with
|
|
||||||
# setDefaultModuleLocation "inventory.instances.${instanceName}.roles.${roleName}.tags.${tagName}";
|
|
||||||
settings = {
|
|
||||||
imports = [
|
|
||||||
machineSettings
|
|
||||||
]; # ++ lib.attrValues (lib.mapAttrs (_tagName: v: v.settings) settingsViaTags);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
) instance.roles;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit (instance) module;
|
|
||||||
inherit resolvedModule instanceRoles;
|
|
||||||
}
|
|
||||||
) inventory.instances or { };
|
|
||||||
|
|
||||||
# Group the instances by the module they resolve to
|
|
||||||
# This is necessary to evaluate the module in a single pass
|
|
||||||
# :: { <module.input>_<module.name> :: [ { name, value } ] }
|
|
||||||
# Since 'perMachine' needs access to all the instances we should include them as a whole
|
|
||||||
grouped = lib.foldlAttrs (
|
|
||||||
acc: instanceName: instance:
|
|
||||||
let
|
|
||||||
inputName = if instance.module.input == null then "<clan-core>" else instance.module.input;
|
|
||||||
id = inputName + "-" + instance.module.name;
|
|
||||||
in
|
|
||||||
acc
|
|
||||||
// {
|
|
||||||
${id} = acc.${id} or [ ] ++ [
|
|
||||||
{
|
|
||||||
inherit instanceName instance;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
) { } importedModuleWithInstances;
|
|
||||||
|
|
||||||
# servicesEval.config.mappedServices.self-A.result.final.jon.nixosModule
|
|
||||||
allMachines = lib.mapAttrs (machineName: _: {
|
|
||||||
# This is the list of nixosModules for each machine
|
|
||||||
machineImports = lib.foldlAttrs (
|
|
||||||
acc: _module_ident: serviceModule:
|
|
||||||
acc ++ [ serviceModule.result.final.${machineName}.nixosModule or { } ]
|
|
||||||
) [ ] servicesEval.config.mappedServices;
|
|
||||||
}) inventory.machines or { };
|
|
||||||
|
|
||||||
evalServices =
|
|
||||||
{ modules, prefix }:
|
|
||||||
lib.evalModules {
|
|
||||||
class = "clan";
|
|
||||||
specialArgs = {
|
|
||||||
inherit clanLib;
|
|
||||||
_ctx = prefix;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
(import ./all-services-wrapper.nix { inherit directory; })
|
|
||||||
]
|
|
||||||
++ modules;
|
|
||||||
};
|
|
||||||
|
|
||||||
servicesEval = evalServices {
|
|
||||||
inherit prefix;
|
|
||||||
modules = [
|
|
||||||
{
|
|
||||||
inherit exportsModule;
|
|
||||||
mappedServices = lib.mapAttrs (_module_ident: instances: {
|
|
||||||
imports = [
|
|
||||||
# Import the resolved module.
|
|
||||||
# i.e. clan.modules.admin
|
|
||||||
{
|
|
||||||
options.module = lib.mkOption {
|
|
||||||
type = lib.types.raw;
|
|
||||||
default = (builtins.head instances).instance.module;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
(builtins.head instances).instance.resolvedModule
|
|
||||||
] # Include all the instances that correlate to the resolved module
|
|
||||||
++ (builtins.map (v: {
|
|
||||||
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
|
||||||
}) instances);
|
|
||||||
}) grouped;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
importedModulesEvaluated = servicesEval.config.mappedServices;
|
|
||||||
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit
|
|
||||||
servicesEval
|
|
||||||
importedModuleWithInstances
|
|
||||||
# Exposed for testing
|
|
||||||
grouped
|
|
||||||
allMachines
|
|
||||||
importedModulesEvaluated
|
|
||||||
;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -7,10 +7,14 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types uniqueStrings;
|
inherit (lib) mkOption types;
|
||||||
inherit (types) attrsWith submoduleWith;
|
inherit (types) attrsWith submoduleWith;
|
||||||
|
|
||||||
errorContext = "Error context: ${lib.concatStringsSep "." _ctx}";
|
errorContext = "Error context: ${lib.concatStringsSep "." _ctx}";
|
||||||
|
# TODO:
|
||||||
|
# Remove once this gets merged upstream; performs in O(n*log(n) instead of O(n^2))
|
||||||
|
# https://github.com/NixOS/nixpkgs/pull/355616/files
|
||||||
|
uniqueStrings = list: builtins.attrNames (builtins.groupBy lib.id list);
|
||||||
/**
|
/**
|
||||||
Merges the role- and machine-settings using the role interface
|
Merges the role- and machine-settings using the role interface
|
||||||
|
|
||||||
|
|||||||
@@ -4,36 +4,8 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
|
||||||
evalModules
|
|
||||||
;
|
|
||||||
|
|
||||||
evalInventory =
|
|
||||||
m:
|
|
||||||
(evalModules {
|
|
||||||
# Static modules
|
|
||||||
modules = [
|
|
||||||
clanLib.inventory.inventoryModule
|
|
||||||
{
|
|
||||||
_file = "test file";
|
|
||||||
tags.all = [ ];
|
|
||||||
tags.nixos = [ ];
|
|
||||||
tags.darwin = [ ];
|
|
||||||
}
|
|
||||||
{
|
|
||||||
modules.test = { };
|
|
||||||
}
|
|
||||||
m
|
|
||||||
];
|
|
||||||
}).config;
|
|
||||||
|
|
||||||
callInventoryAdapter =
|
|
||||||
inventoryModule:
|
|
||||||
let
|
|
||||||
inventory = evalInventory inventoryModule;
|
|
||||||
flakeInputsFixture = {
|
flakeInputsFixture = {
|
||||||
self.clan.modules = inventoryModule.modules or { };
|
|
||||||
# Example upstream module
|
|
||||||
upstream.clan.modules = {
|
upstream.clan.modules = {
|
||||||
uzzi = {
|
uzzi = {
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
@@ -43,24 +15,42 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
|
||||||
clanLib.inventory.mapInstances {
|
createTestClan =
|
||||||
directory = ./.;
|
testClan:
|
||||||
clanCoreModules = { };
|
let
|
||||||
flakeInputs = flakeInputsFixture;
|
res = clanLib.clan ({
|
||||||
inherit inventory;
|
# Static / mocked
|
||||||
exportsModule = { };
|
specialArgs = {
|
||||||
|
clan-core = {
|
||||||
|
clan.modules = { };
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
self.inputs = flakeInputsFixture // {
|
||||||
|
self.clan = res.config;
|
||||||
|
};
|
||||||
|
directory = ./.;
|
||||||
|
exportsModule = { };
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
testClan
|
||||||
|
];
|
||||||
|
});
|
||||||
|
in
|
||||||
|
res;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
extraModules = import ./extraModules.nix { inherit clanLib; };
|
extraModules = import ./extraModules.nix { inherit clanLib; };
|
||||||
exports = import ./exports.nix { inherit lib clanLib; };
|
exports = import ./exports.nix { inherit lib clanLib; };
|
||||||
settings = import ./settings.nix { inherit lib callInventoryAdapter; };
|
settings = import ./settings.nix { inherit lib createTestClan; };
|
||||||
specialArgs = import ./specialArgs.nix { inherit lib callInventoryAdapter; };
|
specialArgs = import ./specialArgs.nix { inherit lib createTestClan; };
|
||||||
resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; };
|
resolve_module_spec = import ./import_module_spec.nix {
|
||||||
|
inherit lib createTestClan;
|
||||||
|
};
|
||||||
test_simple =
|
test_simple =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -71,7 +61,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
# User config
|
# User config
|
||||||
instances."instance_foo" = {
|
inventory.instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "simple-module";
|
name = "simple-module";
|
||||||
};
|
};
|
||||||
@@ -81,7 +71,7 @@ in
|
|||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = res.importedModulesEvaluated ? "<clan-core>-simple-module";
|
expr = res.config._services.mappedServices ? "<clan-core>-simple-module";
|
||||||
expected = true;
|
expected = true;
|
||||||
inherit res;
|
inherit res;
|
||||||
};
|
};
|
||||||
@@ -92,7 +82,7 @@ in
|
|||||||
# All instances should be included within one evaluation to make all of them available
|
# All instances should be included within one evaluation to make all of them available
|
||||||
test_module_grouping =
|
test_module_grouping =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -112,18 +102,19 @@ in
|
|||||||
|
|
||||||
perMachine = { }: { };
|
perMachine = { }: { };
|
||||||
};
|
};
|
||||||
|
|
||||||
# User config
|
# User config
|
||||||
instances."instance_foo" = {
|
inventory.instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
instances."instance_bar" = {
|
inventory.instances."instance_bar" = {
|
||||||
module = {
|
module = {
|
||||||
name = "B";
|
name = "B";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
instances."instance_baz" = {
|
inventory.instances."instance_baz" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
};
|
};
|
||||||
@@ -133,16 +124,16 @@ in
|
|||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.mapAttrs (_n: v: builtins.length v) res.grouped;
|
expr = lib.attrNames res.config._services.mappedServices;
|
||||||
expected = {
|
expected = [
|
||||||
"<clan-core>-A" = 2;
|
"<clan-core>-A"
|
||||||
"<clan-core>-B" = 1;
|
"<clan-core>-B"
|
||||||
};
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
test_creates_all_instances =
|
test_creates_all_instances =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -154,6 +145,7 @@ in
|
|||||||
|
|
||||||
perMachine = { }: { };
|
perMachine = { }: { };
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
@@ -173,11 +165,12 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.attrNames res.importedModulesEvaluated.self-A.instances;
|
expr = lib.attrNames res.config._services.mappedServices.self-A.instances;
|
||||||
expected = [
|
expected = [
|
||||||
"instance_bar"
|
"instance_bar"
|
||||||
"instance_foo"
|
"instance_foo"
|
||||||
@@ -187,7 +180,7 @@ in
|
|||||||
# Membership via roles
|
# Membership via roles
|
||||||
test_add_machines_directly =
|
test_add_machines_directly =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -202,6 +195,7 @@ in
|
|||||||
|
|
||||||
# perMachine = {}: {};
|
# perMachine = {}: {};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = { };
|
jon = { };
|
||||||
sara = { };
|
sara = { };
|
||||||
@@ -229,11 +223,12 @@ in
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.attrNames res.importedModulesEvaluated.self-A.result.allMachines;
|
expr = lib.attrNames res.config._services.mappedServices.self-A.result.allMachines;
|
||||||
expected = [
|
expected = [
|
||||||
"jon"
|
"jon"
|
||||||
"sara"
|
"sara"
|
||||||
@@ -243,7 +238,7 @@ in
|
|||||||
# Membership via tags
|
# Membership via tags
|
||||||
test_add_machines_via_tags =
|
test_add_machines_via_tags =
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||||
@@ -257,6 +252,7 @@ in
|
|||||||
|
|
||||||
# perMachine = {}: {};
|
# perMachine = {}: {};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = {
|
jon = {
|
||||||
tags = [ "foo" ];
|
tags = [ "foo" ];
|
||||||
@@ -281,11 +277,12 @@ in
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Test that the module is mapped into the output
|
# Test that the module is mapped into the output
|
||||||
# We might change the attribute name in the future
|
# We might change the attribute name in the future
|
||||||
expr = lib.attrNames res.importedModulesEvaluated.self-A.result.allMachines;
|
expr = lib.attrNames res.config._services.mappedServices.self-A.result.allMachines;
|
||||||
expected = [
|
expected = [
|
||||||
"jon"
|
"jon"
|
||||||
"sara"
|
"sara"
|
||||||
@@ -293,6 +290,9 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
machine_imports = import ./machine_imports.nix { inherit lib clanLib; };
|
machine_imports = import ./machine_imports.nix { inherit lib clanLib; };
|
||||||
per_machine_args = import ./per_machine_args.nix { inherit lib callInventoryAdapter; };
|
per_machine_args = import ./per_machine_args.nix { inherit lib createTestClan; };
|
||||||
per_instance_args = import ./per_instance_args.nix { inherit lib callInventoryAdapter; };
|
per_instance_args = import ./per_instance_args.nix {
|
||||||
|
inherit lib;
|
||||||
|
callInventoryAdapter = createTestClan;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ callInventoryAdapter, ... }:
|
{ createTestClan, ... }:
|
||||||
let
|
let
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
@@ -23,12 +23,15 @@ let
|
|||||||
|
|
||||||
resolve =
|
resolve =
|
||||||
spec:
|
spec:
|
||||||
callInventoryAdapter {
|
createTestClan {
|
||||||
inherit modules machines;
|
inherit modules;
|
||||||
|
inventory = {
|
||||||
|
inherit machines;
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = spec;
|
module = spec;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_import_local_module_by_name = {
|
test_import_local_module_by_name = {
|
||||||
@@ -36,25 +39,16 @@ in
|
|||||||
(resolve {
|
(resolve {
|
||||||
name = "A";
|
name = "A";
|
||||||
input = "self";
|
input = "self";
|
||||||
}).importedModuleWithInstances.instance_foo.resolvedModule;
|
}).config._services.mappedServices.self-A.manifest.name;
|
||||||
expected = {
|
expected = "network";
|
||||||
_class = "clan.service";
|
|
||||||
manifest = {
|
|
||||||
name = "network";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
test_import_remote_module_by_name = {
|
test_import_remote_module_by_name = {
|
||||||
expr =
|
expr =
|
||||||
(resolve {
|
(resolve {
|
||||||
name = "uzzi";
|
name = "uzzi";
|
||||||
input = "upstream";
|
input = "upstream";
|
||||||
}).importedModuleWithInstances.instance_foo.resolvedModule;
|
}).config._services.mappedServices.upstream-uzzi.manifest.name;
|
||||||
expected = {
|
expected = "uzzi-from-upstream";
|
||||||
_class = "clan.service";
|
|
||||||
manifest = {
|
|
||||||
name = "uzzi-from-upstream";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ let
|
|||||||
sara = { };
|
sara = { };
|
||||||
};
|
};
|
||||||
res = callInventoryAdapter {
|
res = callInventoryAdapter {
|
||||||
inherit modules machines;
|
inherit modules;
|
||||||
|
|
||||||
|
inventory = {
|
||||||
|
inherit machines;
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
@@ -93,6 +96,7 @@ let
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1 { imports = [ { instanceName = "instance_foo"; machine = { name = "jon"; roles = [ "controller" "pe 1 null
|
1 { imports = [ { instanceName = "instance_foo"; machine = { name = "jon"; roles = [ "controller" "pe 1 null
|
||||||
@@ -105,9 +109,10 @@ in
|
|||||||
{
|
{
|
||||||
# settings should evaluate
|
# settings should evaluate
|
||||||
test_per_instance_arguments = {
|
test_per_instance_arguments = {
|
||||||
|
inherit res;
|
||||||
expr = {
|
expr = {
|
||||||
instanceName =
|
instanceName =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances."instance_foo".allMachines.jon.passthru.instanceName;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances."instance_foo".allMachines.jon.passthru.instanceName;
|
||||||
|
|
||||||
# settings are specific.
|
# settings are specific.
|
||||||
# Below we access:
|
# Below we access:
|
||||||
@@ -115,11 +120,11 @@ in
|
|||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = jon
|
# machines = jon
|
||||||
settings =
|
settings =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.settings;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.settings;
|
||||||
machine =
|
machine =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.machine;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.machine;
|
||||||
roles =
|
roles =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.roles;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.roles;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
instanceName = "instance_foo";
|
instanceName = "instance_foo";
|
||||||
@@ -160,9 +165,9 @@ in
|
|||||||
|
|
||||||
# TODO: Cannot be tested like this anymore
|
# TODO: Cannot be tested like this anymore
|
||||||
test_per_instance_settings_vendoring = {
|
test_per_instance_settings_vendoring = {
|
||||||
x = res.importedModulesEvaluated.self-A;
|
x = res.config._services.mappedServices.self-A;
|
||||||
expr =
|
expr =
|
||||||
res.importedModulesEvaluated.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.vendoredSettings;
|
res.config._services.mappedServices.self-A.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.passthru.vendoredSettings;
|
||||||
expected = {
|
expected = {
|
||||||
timeout = "config.thing";
|
timeout = "config.thing";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ lib, callInventoryAdapter }:
|
{ lib, createTestClan }:
|
||||||
let
|
let
|
||||||
# Authored module
|
# Authored module
|
||||||
# A minimal module looks like this
|
# A minimal module looks like this
|
||||||
@@ -39,8 +39,11 @@ let
|
|||||||
jon = { };
|
jon = { };
|
||||||
sara = { };
|
sara = { };
|
||||||
};
|
};
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
inherit modules machines;
|
inherit modules;
|
||||||
|
inventory = {
|
||||||
|
|
||||||
|
inherit machines;
|
||||||
instances."instance_foo" = {
|
instances."instance_foo" = {
|
||||||
module = {
|
module = {
|
||||||
name = "A";
|
name = "A";
|
||||||
@@ -70,6 +73,7 @@ let
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -79,7 +83,7 @@ in
|
|||||||
inherit res;
|
inherit res;
|
||||||
expr = {
|
expr = {
|
||||||
hasMachineSettings =
|
hasMachineSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon
|
||||||
? settings;
|
? settings;
|
||||||
|
|
||||||
# settings are specific.
|
# settings are specific.
|
||||||
@@ -88,10 +92,10 @@ in
|
|||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = jon
|
# machines = jon
|
||||||
specificMachineSettings =
|
specificMachineSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon.settings;
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer.machines.jon.settings;
|
||||||
|
|
||||||
hasRoleSettings =
|
hasRoleSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer
|
||||||
? settings;
|
? settings;
|
||||||
|
|
||||||
# settings are specific.
|
# settings are specific.
|
||||||
@@ -100,7 +104,7 @@ in
|
|||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = *
|
# machines = *
|
||||||
specificRoleSettings =
|
specificRoleSettings =
|
||||||
res.importedModulesEvaluated.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer;
|
res.config._services.mappedServices.self-A.result.allMachines.jon.passthru.instances.instance_foo.roles.peer;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
hasMachineSettings = true;
|
hasMachineSettings = true;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{ callInventoryAdapter, lib, ... }:
|
{ createTestClan, lib, ... }:
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
modules."A" = {
|
modules."A" = {
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
manifest = {
|
manifest = {
|
||||||
@@ -21,6 +21,8 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
|
|
||||||
machines = {
|
machines = {
|
||||||
jon = { };
|
jon = { };
|
||||||
sara = { };
|
sara = { };
|
||||||
@@ -41,8 +43,9 @@ let
|
|||||||
roles.peer.machines.sara = { };
|
roles.peer.machines.sara = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config = res.servicesEval.config.mappedServices.self-A;
|
config = res.config._services.mappedServices.self-A;
|
||||||
|
|
||||||
#
|
#
|
||||||
applySettings =
|
applySettings =
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{ callInventoryAdapter, lib, ... }:
|
{ createTestClan, lib, ... }:
|
||||||
let
|
let
|
||||||
res = callInventoryAdapter {
|
res = createTestClan {
|
||||||
modules."A" = m: {
|
modules."A" = m: {
|
||||||
_class = "clan.service";
|
_class = "clan.service";
|
||||||
config = {
|
config = {
|
||||||
@@ -14,6 +14,7 @@ let
|
|||||||
default = m;
|
default = m;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
inventory = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = { };
|
jon = { };
|
||||||
};
|
};
|
||||||
@@ -25,8 +26,9 @@ let
|
|||||||
roles.peer.machines.jon = { };
|
roles.peer.machines.jon = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
specialArgs = lib.attrNames res.servicesEval.config.mappedServices.self-A.test.specialArgs;
|
specialArgs = lib.attrNames res.config._services.mappedServices.self-A.test.specialArgs;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test_simple = {
|
test_simple = {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
imports = [
|
imports = [
|
||||||
./top-level-interface.nix
|
./top-level-interface.nix
|
||||||
./module.nix
|
./module.nix
|
||||||
|
./distributed-services.nix
|
||||||
./checks.nix
|
./checks.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
163
modules/clan/distributed-services.nix
Normal file
163
modules/clan/distributed-services.nix
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
clanLib,
|
||||||
|
config,
|
||||||
|
clan-core,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
# Keep a reference to top-level
|
||||||
|
clanConfig = config;
|
||||||
|
|
||||||
|
inventory = clanConfig.inventory;
|
||||||
|
flakeInputs = clanConfig.self.inputs;
|
||||||
|
clanCoreModules = clan-core.clan.modules;
|
||||||
|
|
||||||
|
grouped = lib.foldlAttrs (
|
||||||
|
acc: instanceName: instance:
|
||||||
|
let
|
||||||
|
inputName = if instance.module.input == null then "<clan-core>" else instance.module.input;
|
||||||
|
id = inputName + "-" + instance.module.name;
|
||||||
|
in
|
||||||
|
acc
|
||||||
|
// {
|
||||||
|
${id} = acc.${id} or [ ] ++ [
|
||||||
|
{
|
||||||
|
inherit instanceName instance;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
) { } importedModuleWithInstances;
|
||||||
|
|
||||||
|
importedModuleWithInstances = lib.mapAttrs (
|
||||||
|
instanceName: instance:
|
||||||
|
let
|
||||||
|
resolvedModule = clanLib.resolveModule {
|
||||||
|
moduleSpec = instance.module;
|
||||||
|
inherit flakeInputs clanCoreModules;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Every instance includes machines via roles
|
||||||
|
# :: { client :: ... }
|
||||||
|
instanceRoles = lib.mapAttrs (
|
||||||
|
roleName: role:
|
||||||
|
let
|
||||||
|
resolvedMachines = clanLib.inventory.resolveTags {
|
||||||
|
members = {
|
||||||
|
# Explicit members
|
||||||
|
machines = lib.attrNames role.machines;
|
||||||
|
# Resolved Members
|
||||||
|
tags = lib.attrNames role.tags;
|
||||||
|
};
|
||||||
|
inherit (inventory) machines;
|
||||||
|
inherit instanceName roleName;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
# instances.<instanceName>.roles.<roleName> =
|
||||||
|
# Remove "tags", they are resolved into "machines"
|
||||||
|
(removeAttrs role [ "tags" ])
|
||||||
|
// {
|
||||||
|
machines = lib.genAttrs resolvedMachines.machines (
|
||||||
|
machineName:
|
||||||
|
let
|
||||||
|
machineSettings = instance.roles.${roleName}.machines.${machineName}.settings or { };
|
||||||
|
in
|
||||||
|
# TODO: tag settings
|
||||||
|
# Wait for this feature until option introspection for 'settings' is done.
|
||||||
|
# This might get too complex to handle otherwise.
|
||||||
|
# settingsViaTags = lib.filterAttrs (
|
||||||
|
# tagName: _: machineHasTag machineName tagName
|
||||||
|
# ) instance.roles.${roleName}.tags;
|
||||||
|
{
|
||||||
|
# TODO: Do we want to wrap settings with
|
||||||
|
# setDefaultModuleLocation "inventory.instances.${instanceName}.roles.${roleName}.tags.${tagName}";
|
||||||
|
settings = {
|
||||||
|
imports = [
|
||||||
|
machineSettings
|
||||||
|
]; # ++ lib.attrValues (lib.mapAttrs (_tagName: v: v.settings) settingsViaTags);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
) instance.roles;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit (instance) module;
|
||||||
|
inherit resolvedModule instanceRoles;
|
||||||
|
}
|
||||||
|
) inventory.instances or { };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
_class = "clan";
|
||||||
|
options._services = mkOption {
|
||||||
|
visible = false;
|
||||||
|
description = ''
|
||||||
|
All service instances
|
||||||
|
|
||||||
|
!!! Danger "Internal API"
|
||||||
|
Do not rely on this API yet.
|
||||||
|
|
||||||
|
- Will be renamed to just 'services' in the future.
|
||||||
|
Once the name can be claimed again.
|
||||||
|
- Structure will change.
|
||||||
|
|
||||||
|
API will be declared as public after beeing simplified.
|
||||||
|
'';
|
||||||
|
type = types.submoduleWith {
|
||||||
|
# TODO: Remove specialArgs
|
||||||
|
specialArgs = {
|
||||||
|
inherit clanLib;
|
||||||
|
};
|
||||||
|
modules = [
|
||||||
|
(import ../../lib/inventory/distributed-service/all-services-wrapper.nix {
|
||||||
|
inherit (clanConfig) directory;
|
||||||
|
})
|
||||||
|
# Dependencies
|
||||||
|
{
|
||||||
|
exportsModule = clanConfig.exportsModule;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# TODO: Rename to "allServices"
|
||||||
|
# All services
|
||||||
|
mappedServices = lib.mapAttrs (_module_ident: instances: {
|
||||||
|
imports = [
|
||||||
|
# Import the resolved module.
|
||||||
|
# i.e. clan.modules.admin
|
||||||
|
{
|
||||||
|
options.module = lib.mkOption {
|
||||||
|
type = lib.types.raw;
|
||||||
|
default = (builtins.head instances).instance.module;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(builtins.head instances).instance.resolvedModule
|
||||||
|
] # Include all the instances that correlate to the resolved module
|
||||||
|
++ (builtins.map (v: {
|
||||||
|
instances.${v.instanceName}.roles = v.instance.instanceRoles;
|
||||||
|
}) instances);
|
||||||
|
}) grouped;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
options._allMachines = mkOption {
|
||||||
|
internal = true;
|
||||||
|
type = types.raw;
|
||||||
|
default = lib.mapAttrs (machineName: _: {
|
||||||
|
# This is the list of nixosModules for each machine
|
||||||
|
machineImports = lib.foldlAttrs (
|
||||||
|
acc: _module_ident: serviceModule:
|
||||||
|
acc ++ [ serviceModule.result.final.${machineName}.nixosModule or { } ]
|
||||||
|
) [ ] config._services.mappedServices;
|
||||||
|
}) inventory.machines or { };
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
clanInternals.inventoryClass.machines = config._allMachines;
|
||||||
|
# clanInternals.inventoryClass.distributedServices = config._services;
|
||||||
|
|
||||||
|
# Exports from distributed services
|
||||||
|
exports = config._services.exports;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -3,12 +3,16 @@
|
|||||||
lib,
|
lib,
|
||||||
clanModule,
|
clanModule,
|
||||||
clanLib,
|
clanLib,
|
||||||
|
clan-core,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
eval = lib.evalModules {
|
eval = lib.evalModules {
|
||||||
modules = [
|
modules = [
|
||||||
clanModule
|
clanModule
|
||||||
];
|
];
|
||||||
|
specialArgs = {
|
||||||
|
self = clan-core;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
evalDocs = pkgs.nixosOptionsDoc {
|
evalDocs = pkgs.nixosOptionsDoc {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ in
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
jsonDocs = import ./eval-docs.nix {
|
jsonDocs = import ./eval-docs.nix {
|
||||||
|
clan-core = self;
|
||||||
inherit
|
inherit
|
||||||
pkgs
|
pkgs
|
||||||
lib
|
lib
|
||||||
|
|||||||
@@ -219,8 +219,6 @@ in
|
|||||||
inherit nixosConfigurations;
|
inherit nixosConfigurations;
|
||||||
inherit darwinConfigurations;
|
inherit darwinConfigurations;
|
||||||
|
|
||||||
exports = config.clanInternals.inventoryClass.distributedServices.servicesEval.config.exports;
|
|
||||||
|
|
||||||
clanInternals = {
|
clanInternals = {
|
||||||
inventoryClass =
|
inventoryClass =
|
||||||
let
|
let
|
||||||
@@ -254,21 +252,9 @@ in
|
|||||||
exportsModule = config.exportsModule;
|
exportsModule = config.exportsModule;
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
{ config, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
staticModules = clan-core.clan.modules;
|
staticModules = clan-core.clan.modules;
|
||||||
|
|
||||||
distributedServices = clanLib.inventory.mapInstances {
|
|
||||||
inherit (config)
|
|
||||||
inventory
|
|
||||||
directory
|
|
||||||
flakeInputs
|
|
||||||
exportsModule
|
|
||||||
;
|
|
||||||
clanCoreModules = clan-core.clan.modules;
|
|
||||||
prefix = [ "distributedServices" ];
|
|
||||||
};
|
|
||||||
machines = config.distributedServices.allMachines;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -67,9 +67,6 @@ in
|
|||||||
type = types.raw;
|
type = types.raw;
|
||||||
};
|
};
|
||||||
|
|
||||||
distributedServices = mkOption {
|
|
||||||
type = types.raw;
|
|
||||||
};
|
|
||||||
inventory = mkOption {
|
inventory = mkOption {
|
||||||
type = types.raw;
|
type = types.raw;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -64,6 +64,9 @@
|
|||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
legacyPackages = {
|
||||||
|
inherit jsonDocs clanModulesViaService;
|
||||||
|
};
|
||||||
packages = {
|
packages = {
|
||||||
inherit module-docs;
|
inherit module-docs;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,151 +11,10 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
|
||||||
mapAttrsToList
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
|
||||||
types
|
|
||||||
splitString
|
|
||||||
stringLength
|
|
||||||
substring
|
|
||||||
;
|
|
||||||
inherit (self) clanLib;
|
|
||||||
|
|
||||||
serviceModules = self.clan.modules;
|
|
||||||
|
|
||||||
baseHref = "/option-search/";
|
baseHref = "/option-search/";
|
||||||
|
|
||||||
getRoles =
|
|
||||||
module:
|
|
||||||
(clanLib.evalService {
|
|
||||||
modules = [ module ];
|
|
||||||
prefix = [ ];
|
|
||||||
}).config.roles;
|
|
||||||
|
|
||||||
getManifest =
|
|
||||||
module:
|
|
||||||
(clanLib.evalService {
|
|
||||||
modules = [ module ];
|
|
||||||
prefix = [ ];
|
|
||||||
}).config.manifest;
|
|
||||||
|
|
||||||
settingsModules = module: mapAttrs (_roleName: roleConfig: roleConfig.interface) (getRoles module);
|
|
||||||
|
|
||||||
# Map each letter to its capitalized version
|
# Map each letter to its capitalized version
|
||||||
capitalizeChar =
|
|
||||||
char:
|
|
||||||
{
|
|
||||||
a = "A";
|
|
||||||
b = "B";
|
|
||||||
c = "C";
|
|
||||||
d = "D";
|
|
||||||
e = "E";
|
|
||||||
f = "F";
|
|
||||||
g = "G";
|
|
||||||
h = "H";
|
|
||||||
i = "I";
|
|
||||||
j = "J";
|
|
||||||
k = "K";
|
|
||||||
l = "L";
|
|
||||||
m = "M";
|
|
||||||
n = "N";
|
|
||||||
o = "O";
|
|
||||||
p = "P";
|
|
||||||
q = "Q";
|
|
||||||
r = "R";
|
|
||||||
s = "S";
|
|
||||||
t = "T";
|
|
||||||
u = "U";
|
|
||||||
v = "V";
|
|
||||||
w = "W";
|
|
||||||
x = "X";
|
|
||||||
y = "Y";
|
|
||||||
z = "Z";
|
|
||||||
}
|
|
||||||
.${char};
|
|
||||||
|
|
||||||
title =
|
|
||||||
name:
|
|
||||||
let
|
|
||||||
# split by -
|
|
||||||
parts = splitString "-" name;
|
|
||||||
# capitalize first letter of each part
|
|
||||||
capitalize = part: (capitalizeChar (substring 0 1 part)) + substring 1 (stringLength part) part;
|
|
||||||
capitalizedParts = map capitalize parts;
|
|
||||||
in
|
|
||||||
builtins.concatStringsSep " " capitalizedParts;
|
|
||||||
|
|
||||||
fakeInstanceOptions =
|
|
||||||
name: module:
|
|
||||||
let
|
|
||||||
manifest = getManifest module;
|
|
||||||
description = ''
|
|
||||||
# ${title name} (Clan Service)
|
|
||||||
|
|
||||||
**${manifest.description}**
|
|
||||||
|
|
||||||
${lib.optionalString (manifest ? readme) manifest.readme}
|
|
||||||
|
|
||||||
${
|
|
||||||
if manifest.categories != [ ] then
|
|
||||||
"Categories: " + builtins.concatStringsSep ", " manifest.categories
|
|
||||||
else
|
|
||||||
"No categories defined"
|
|
||||||
}
|
|
||||||
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
instances.${name} = lib.mkOption {
|
|
||||||
inherit description;
|
|
||||||
type = types.submodule {
|
|
||||||
options.roles = mapAttrs (
|
|
||||||
roleName: roleSettingsModule:
|
|
||||||
mkOption {
|
|
||||||
type = types.submodule {
|
|
||||||
_file = "docs flake-module";
|
|
||||||
imports = [
|
|
||||||
{ _module.args = { inherit clanLib; }; }
|
|
||||||
(import ../../modules/inventoryClass/role.nix {
|
|
||||||
nestedSettingsOption = mkOption {
|
|
||||||
type = types.raw;
|
|
||||||
description = ''
|
|
||||||
See [instances.${name}.roles.${roleName}.settings](${baseHref}?option_scope=0&option=inventory.instances.${name}.roles.${roleName}.settings)
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
settingsOption = mkOption {
|
|
||||||
type = types.submoduleWith {
|
|
||||||
modules = [ roleSettingsModule ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
) (settingsModules module);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
docModules = [
|
|
||||||
{
|
|
||||||
inherit self;
|
|
||||||
}
|
|
||||||
self.modules.clan.default
|
|
||||||
{
|
|
||||||
options.inventory = lib.mkOption {
|
|
||||||
type = types.submoduleWith {
|
|
||||||
modules = [
|
|
||||||
{ noInstanceOptions = true; }
|
|
||||||
]
|
|
||||||
++ mapAttrsToList fakeInstanceOptions serviceModules;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
baseModule =
|
baseModule =
|
||||||
# Module
|
# Module
|
||||||
@@ -208,12 +67,6 @@
|
|||||||
title = "Clan Options";
|
title = "Clan Options";
|
||||||
# scopes = mapAttrsToList mkScope serviceModules;
|
# scopes = mapAttrsToList mkScope serviceModules;
|
||||||
scopes = [
|
scopes = [
|
||||||
{
|
|
||||||
inherit baseHref;
|
|
||||||
name = "Flake Options (clan.nix file)";
|
|
||||||
modules = docModules;
|
|
||||||
urlPrefix = "https://git.clan.lol/clan/clan-core/src/branch/main/";
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
name = "Machine Options (clan.core NixOS options)";
|
name = "Machine Options (clan.core NixOS options)";
|
||||||
optionsJSON = "${coreOptions}/share/doc/nixos/options.json";
|
optionsJSON = "${coreOptions}/share/doc/nixos/options.json";
|
||||||
|
|||||||
Reference in New Issue
Block a user