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 { distributedServices = clanLib.inventory.mapInstances {
inherit (clanConfig) inventory exportsModule; inherit (clanConfig) inventory exportsModule;
inherit flakeInputs; inherit flakeInputs directory;
clanCoreModules = clan-core.clan.modules; clanCoreModules = clan-core.clan.modules;
prefix = [ "distributedServices" ]; prefix = [ "distributedServices" ];
}; };

View File

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

View File

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

View File

@@ -2,6 +2,7 @@
lib, lib,
config, config,
_ctx, _ctx,
directory,
... ...
}: }:
let let
@@ -212,7 +213,7 @@ in
options.extraModules = lib.mkOption { options.extraModules = lib.mkOption {
default = [ ]; default = [ ];
type = types.listOf (types.deferredModule); type = types.listOf (types.either types.deferredModule types.str);
}; };
}) })
]; ];
@@ -755,10 +756,14 @@ in
instanceRes instanceRes
// { // {
nixosModule = { nixosModule = {
imports = [ imports =
# Result of the applied 'perInstance = {...}: { nixosModule = { ... }; }' [
instanceRes.nixosModule # Result of the applied 'perInstance = {...}: { nixosModule = { ... }; }'
] ++ instanceCfg.roles.${roleName}.extraModules; 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 in
clanLib.inventory.mapInstances { clanLib.inventory.mapInstances {
directory = ./.;
clanCoreModules = { }; clanCoreModules = { };
flakeInputs = flakeInputsFixture; flakeInputs = flakeInputsFixture;
inherit inventory; inherit inventory;
@@ -52,6 +53,7 @@ let
}; };
in in
{ {
extraModules = import ./extraModules.nix { inherit clanLib; };
exports = import ./exports.nix { inherit lib clanLib; }; exports = import ./exports.nix { inherit lib clanLib; };
resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; }; resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; };
test_simple = 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;
};
}