Merge pull request 'Inventory: fixes' (#2104) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
@@ -141,9 +141,9 @@ let
|
|||||||
throw "Module doesn't have role: '${role}'. Path: ${path} not found."
|
throw "Module doesn't have role: '${role}'. Path: ${path} not found."
|
||||||
) inverseRoles.${machineName} or [ ];
|
) inverseRoles.${machineName} or [ ];
|
||||||
|
|
||||||
roleServiceConfigs = builtins.map (
|
roleServiceConfigs = builtins.filter (m: m != { }) (
|
||||||
role: serviceConfig.roles.${role}.config or { }
|
builtins.map (role: serviceConfig.roles.${role}.config or { }) inverseRoles.${machineName} or [ ]
|
||||||
) inverseRoles.${machineName} or [ ];
|
);
|
||||||
|
|
||||||
customImports = map (s: "${directory}/${s}") (
|
customImports = map (s: "${directory}/${s}") (
|
||||||
globalImports ++ machineImports ++ roleServiceImports
|
globalImports ++ machineImports ++ roleServiceImports
|
||||||
@@ -155,6 +155,9 @@ let
|
|||||||
++ [
|
++ [
|
||||||
{
|
{
|
||||||
imports = [ clan-core.clanModules.${serviceName} ] ++ roleModules ++ customImports;
|
imports = [ clan-core.clanModules.${serviceName} ] ++ roleModules ++ customImports;
|
||||||
|
}
|
||||||
|
(lib.optionalAttrs (globalConfig != { } || machineServiceConfig != { } || roleServiceConfigs != [ ])
|
||||||
|
{
|
||||||
config.clan.${serviceName} = lib.mkMerge (
|
config.clan.${serviceName} = lib.mkMerge (
|
||||||
[
|
[
|
||||||
globalConfig
|
globalConfig
|
||||||
@@ -163,6 +166,8 @@ let
|
|||||||
++ roleServiceConfigs
|
++ roleServiceConfigs
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
{
|
{
|
||||||
config.clan.inventory.services.${serviceName}.${instanceName} = {
|
config.clan.inventory.services.${serviceName}.${instanceName} = {
|
||||||
roles = resolvedRoles;
|
roles = resolvedRoles;
|
||||||
|
|||||||
@@ -13,6 +13,20 @@ let
|
|||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
metaOptionsWith = name: {
|
||||||
|
name = lib.mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = name;
|
||||||
|
};
|
||||||
|
description = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
};
|
||||||
|
icon = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
moduleConfig = lib.mkOption {
|
moduleConfig = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
@@ -64,9 +78,12 @@ in
|
|||||||
machines = lib.mkOption {
|
machines = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.submodule {
|
types.submodule (
|
||||||
|
{ name, ... }:
|
||||||
|
{
|
||||||
options = {
|
options = {
|
||||||
inherit (metaOptions) name description icon;
|
inherit (metaOptionsWith name) name description icon;
|
||||||
|
|
||||||
tags = lib.mkOption {
|
tags = lib.mkOption {
|
||||||
|
|
||||||
default = [ ];
|
default = [ ];
|
||||||
@@ -84,6 +101,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,8 +109,10 @@ in
|
|||||||
default = { };
|
default = { };
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.attrsOf (
|
types.attrsOf (
|
||||||
types.submodule {
|
types.submodule (
|
||||||
options.meta = metaOptions;
|
{ name, ... }:
|
||||||
|
{
|
||||||
|
options.meta = metaOptionsWith name;
|
||||||
options.imports = importsOption;
|
options.imports = importsOption;
|
||||||
options.config = moduleConfig;
|
options.config = moduleConfig;
|
||||||
options.machines = lib.mkOption {
|
options.machines = lib.mkOption {
|
||||||
@@ -124,6 +144,7 @@ in
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ in
|
|||||||
not_used_machine = builtins.length configs.not_used_machine;
|
not_used_machine = builtins.length configs.not_used_machine;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
client_1_machine = 4;
|
client_1_machine = 5;
|
||||||
client_2_machine = 4;
|
client_2_machine = 5;
|
||||||
not_used_machine = 2;
|
not_used_machine = 2;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user