deps: init poc
This commit is contained in:
@@ -228,6 +228,38 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
serviceOverrides = lib.mkOption {
|
||||
type = types.attrsOf (types.submoduleWith {
|
||||
modules = [
|
||||
{
|
||||
options.dependencies = lib.mkOption {
|
||||
type = types.attrsOf types.raw;
|
||||
description = "Override a dependencies of this service";
|
||||
};
|
||||
}
|
||||
];
|
||||
});
|
||||
default = { };
|
||||
description = ''
|
||||
Override/inject dependencies to a service.
|
||||
|
||||
Example:
|
||||
|
||||
```nix
|
||||
{
|
||||
servicesOverrides = {
|
||||
# Override need to be done by manifest name to avoid ambiguity
|
||||
"clan-core/hello-world" = {
|
||||
dependencies = {
|
||||
home-manager = inputs.home-manager-v2;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
'';
|
||||
};
|
||||
|
||||
inventory = lib.mkOption {
|
||||
type = types.submoduleWith {
|
||||
modules = [
|
||||
|
||||
@@ -248,7 +248,7 @@ in
|
||||
staticModules = clan-core.clan.modules;
|
||||
|
||||
distributedServices = clanLib.inventory.mapInstances {
|
||||
inherit (clanConfig) inventory exportsModule;
|
||||
inherit (clanConfig) inventory exportsModule serviceOverrides;
|
||||
inherit flakeInputs directory;
|
||||
clanCoreModules = clan-core.clan.modules;
|
||||
prefix = [ "distributedServices" ];
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
# TODO: consume directly from clan.config
|
||||
directory,
|
||||
serviceOverrides,
|
||||
}:
|
||||
{
|
||||
lib,
|
||||
@@ -31,10 +32,12 @@ in
|
||||
(
|
||||
{ name, ... }:
|
||||
{
|
||||
_module.args._ctx = [ name ];
|
||||
_module.args.exports = config.exports;
|
||||
_module.args.directory = directory;
|
||||
|
||||
_module.args = {
|
||||
_ctx = [ name ];
|
||||
exports = config.exports;
|
||||
directory = directory;
|
||||
inherit (specialArgs) clanLib _unsafe;
|
||||
};
|
||||
}
|
||||
)
|
||||
./service-module.nix
|
||||
@@ -43,6 +46,9 @@ in
|
||||
inherit (specialArgs) clanLib;
|
||||
prefix = _ctx;
|
||||
})
|
||||
(service: {
|
||||
dependencies = lib.mapAttrs (n: v: { resolved = v; }) serviceOverrides.${service.config.manifest.name}.dependencies or { };
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -26,8 +26,9 @@ in
|
||||
inventory,
|
||||
directory,
|
||||
clanCoreModules,
|
||||
prefix ? [ ],
|
||||
exportsModule,
|
||||
prefix ? [ ],
|
||||
serviceOverrides ? { },
|
||||
}:
|
||||
let
|
||||
# machineHasTag = machineName: tagName: lib.elem tagName inventory.machines.${machineName}.tags;
|
||||
@@ -127,9 +128,10 @@ in
|
||||
specialArgs = {
|
||||
inherit clanLib;
|
||||
_ctx = prefix;
|
||||
_unsafe.flakeInputs = flakeInputs;
|
||||
};
|
||||
modules = [
|
||||
(import ./all-services-wrapper.nix { inherit directory; })
|
||||
(import ./all-services-wrapper.nix { inherit directory serviceOverrides; })
|
||||
]
|
||||
++ modules;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
lib,
|
||||
config,
|
||||
_ctx,
|
||||
_unsafe,
|
||||
directory,
|
||||
exports,
|
||||
...
|
||||
@@ -106,6 +107,10 @@ let
|
||||
in
|
||||
{
|
||||
options = {
|
||||
|
||||
debug = mkOption {
|
||||
default = _unsafe.flakeInputs;
|
||||
};
|
||||
# Option to disable some behavior during docs rendering
|
||||
_docs_rendering = mkOption {
|
||||
default = false;
|
||||
@@ -113,6 +118,54 @@ in
|
||||
type = types.bool;
|
||||
};
|
||||
|
||||
dependencies = mkOption {
|
||||
type = types.attrsWith {
|
||||
placeholder = "dependencyName";
|
||||
elemType = types.submoduleWith {
|
||||
modules = [
|
||||
({name,...}@dep: {
|
||||
options.name = mkOption {
|
||||
default = name;
|
||||
type = types.str;
|
||||
description = "The name of the dependency, usually the input name.";
|
||||
};
|
||||
options.resolved = mkOption {
|
||||
type = types.raw;
|
||||
default = _unsafe.flakeInputs.${dep.config.name} or (throw ''
|
||||
The dependency '${dep.config.name}' could not be found in the flake inputs.
|
||||
|
||||
This module requires '${dep.config.name}' to be present
|
||||
Fixes:
|
||||
- Add '${dep.config.name}' to the flake inputs
|
||||
- Inject a custom dependency via 'clan.serviceOverrides.<manifest-name>.dependencies.${dep.config.name} = ...'
|
||||
'');
|
||||
description = ''
|
||||
The resolved value of the dependency.
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
description = ''
|
||||
Dependencies of this service.
|
||||
|
||||
Can be declared via `clan.lib.mkDependency`.
|
||||
|
||||
```nix
|
||||
{
|
||||
home-manager = clan.lib.mkDependency {
|
||||
name = "home-manager";
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
This will map `inputs.home-manager` to `dependencies.home-manager`.
|
||||
The dependency can then be safely accessed via `config.dependencies.home-manager` from the toplevel arguments of this module.
|
||||
'';
|
||||
default = { };
|
||||
};
|
||||
|
||||
instances = mkOption {
|
||||
visible = false;
|
||||
defaultText = "Throws: 'The service must define its instances' when not defined";
|
||||
|
||||
Reference in New Issue
Block a user