Merge pull request 'services: fix extraModules as path' (#4422) from fix-extra-modules into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4422
This commit is contained in:
hsjobeki
2025-07-21 17:56:58 +00:00
7 changed files with 60 additions and 10 deletions

View File

@@ -247,7 +247,7 @@ in
{
distributedServices = clanLib.inventory.mapInstances {
inherit (clanConfig) inventory exportsModule;
inherit flakeInputs;
inherit flakeInputs directory;
clanCoreModules = clan-core.clan.modules;
prefix = [ "distributedServices" ];
};

View File

@@ -1,4 +1,8 @@
# Wraps all services in one fixed point module
{
# TODO: consume directly from clan.config
directory,
}:
{
lib,
config,
@@ -29,6 +33,8 @@ in
{
_module.args._ctx = [ name ];
_module.args.exports' = config.exports;
_module.args.directory = directory;
}
)
./service-module.nix
@@ -71,8 +77,5 @@ in
};
default = { };
};
debug = mkOption {
default = lib.mapAttrsToList (_: service: service.exports) config.mappedServices;
};
};
}

View File

@@ -24,6 +24,7 @@ in
flakeInputs,
# The clan inventory
inventory,
directory,
clanCoreModules,
prefix ? [ ],
exportsModule,
@@ -128,7 +129,7 @@ in
_ctx = prefix;
};
modules = [
./all-services-wrapper.nix
(import ./all-services-wrapper.nix { inherit directory; })
] ++ modules;
};

View File

@@ -2,6 +2,7 @@
lib,
config,
_ctx,
directory,
...
}:
let
@@ -212,7 +213,7 @@ in
options.extraModules = lib.mkOption {
default = [ ];
type = types.listOf (types.deferredModule);
type = types.listOf (types.either types.deferredModule types.str);
};
})
];
@@ -755,10 +756,14 @@ in
instanceRes
// {
nixosModule = {
imports = [
# Result of the applied 'perInstance = {...}: { nixosModule = { ... }; }'
instanceRes.nixosModule
] ++ instanceCfg.roles.${roleName}.extraModules;
imports =
[
# Result of the applied 'perInstance = {...}: { nixosModule = { ... }; }'
instanceRes.nixosModule
]
++ (map (
s: if builtins.typeOf s == "string" then "${directory}/${s}" else s
) instanceCfg.roles.${roleName}.extraModules);
};
}

View File

@@ -45,6 +45,7 @@ let
};
in
clanLib.inventory.mapInstances {
directory = ./.;
clanCoreModules = { };
flakeInputs = flakeInputsFixture;
inherit inventory;
@@ -52,6 +53,7 @@ let
};
in
{
extraModules = import ./extraModules.nix { inherit clanLib; };
exports = import ./exports.nix { inherit lib clanLib; };
resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; };
test_simple =

View File

@@ -0,0 +1,33 @@
{ clanLib }:
let
clan = clanLib.clan {
self = { };
directory = ./.;
machines.jon = {
nixpkgs.hostPlatform = "x86_64-linux";
};
# A module that adds exports perMachine
modules.A = {
manifest.name = "A";
roles.peer = { };
};
inventory = {
instances.A = {
module.input = "self";
roles.peer.tags.all = { };
roles.peer.extraModules = [ ./oneOption.nix ];
};
};
};
in
{
test_1 = {
inherit clan;
expr = clan.config.nixosConfigurations.jon.config.testDebug;
expected = 42;
};
}

View File

@@ -0,0 +1,6 @@
{ lib, ... }:
{
options.testDebug = lib.mkOption {
default = 42;
};
}