Merge pull request 'modules-1' (#5598) from modules-1 into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5598
This commit is contained in:
hsjobeki
2025-10-20 16:56:29 +00:00
4 changed files with 74 additions and 4 deletions

View File

@@ -27,14 +27,16 @@ in
placeholder = "mappedServiceName";
elemType = submoduleWith {
class = "clan.service";
specialArgs = {
exports = config.exports;
directory = directory;
clanLib = specialArgs.clanLib;
};
modules = [
(
{ name, ... }:
{
_module.args._ctx = [ name ];
_module.args.exports = config.exports;
_module.args.directory = directory;
}
)
./service-module.nix

View File

@@ -56,6 +56,7 @@ in
extraModules = import ./extraModules.nix { inherit clanLib; };
exports = import ./exports.nix { inherit lib clanLib; };
settings = import ./settings.nix { inherit lib callInventoryAdapter; };
specialArgs = import ./specialArgs.nix { inherit lib callInventoryAdapter; };
resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; };
test_simple =
let

View File

@@ -0,0 +1,40 @@
{ callInventoryAdapter, lib, ... }:
let
res = callInventoryAdapter {
modules."A" = m: {
_class = "clan.service";
config = {
manifest = {
name = "network";
};
roles.default = { };
};
options.test = lib.mkOption {
default = m;
};
};
machines = {
jon = { };
};
instances."instance_foo" = {
module = {
name = "A";
input = "self";
};
roles.peer.machines.jon = { };
};
};
specialArgs = lib.attrNames res.servicesEval.config.mappedServices.self-A.test.specialArgs;
in
{
test_simple = {
expr = specialArgs;
expected = [
"clanLib"
"directory"
"exports"
];
};
}

View File

@@ -38,7 +38,34 @@
(pkgs.nixosOptionsDoc {
options =
(self.clanLib.evalService {
modules = [ { _docs_rendering = true; } ];
modules = [
{ _docs_rendering = true; }
{
options."#specialArgs" = lib.mkOption {
description = ''
Adidtional arguments passed to the module. Often referred to as `specialArgs`.
```nix
{
# root directory of the clan
directory,
# clanLib - The clan library functions
clanLib,
# exports from all services
exports,
...
}:
{
_class = "clan.service";
manifest.name = "example-service";
# ... elided
}
```
'';
};
}
];
prefix = [ ];
}).options;
warningsAreErrors = true;