Inventory: add global imports
This commit is contained in:
@@ -106,7 +106,10 @@ let
|
|||||||
|
|
||||||
# map from machine name to service configuration
|
# map from machine name to service configuration
|
||||||
# { ${machineName} :: Config }
|
# { ${machineName} :: Config }
|
||||||
serviceConfigs = buildInventory mergedInventory;
|
serviceConfigs = buildInventory {
|
||||||
|
inventory = mergedInventory;
|
||||||
|
inherit directory;
|
||||||
|
};
|
||||||
|
|
||||||
machinesDirs = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (
|
machinesDirs = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (
|
||||||
builtins.readDir (directory + /machines)
|
builtins.readDir (directory + /machines)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Generate partial NixOS configurations for every machine in the inventory
|
# Generate partial NixOS configurations for every machine in the inventory
|
||||||
# This function is responsible for generating the module configuration for every machine in the inventory.
|
# This function is responsible for generating the module configuration for every machine in the inventory.
|
||||||
{ lib, clan-core }:
|
{ lib, clan-core }:
|
||||||
inventory:
|
{ inventory, directory }:
|
||||||
let
|
let
|
||||||
machines = machinesFromInventory inventory;
|
machines = machinesFromInventory inventory;
|
||||||
|
|
||||||
@@ -72,6 +72,12 @@ let
|
|||||||
machineServiceConfig = (serviceConfig.machines.${machineName} or { }).config or { };
|
machineServiceConfig = (serviceConfig.machines.${machineName} or { }).config or { };
|
||||||
globalConfig = serviceConfig.config or { };
|
globalConfig = serviceConfig.config or { };
|
||||||
|
|
||||||
|
globalImports = serviceConfig.imports or [ ];
|
||||||
|
machineImports = serviceConfig.machines.${machineName}.imports or [ ];
|
||||||
|
roleServiceImports = builtins.foldl' (
|
||||||
|
acc: role: acc ++ serviceConfig.roles.${role}.imports or [ ]
|
||||||
|
) [ ] inverseRoles.${machineName} or [ ];
|
||||||
|
|
||||||
# TODO: maybe optimize this dont lookup the role in inverse roles. Imports are not lazy
|
# TODO: maybe optimize this dont lookup the role in inverse roles. Imports are not lazy
|
||||||
roleModules = builtins.map (
|
roleModules = builtins.map (
|
||||||
role:
|
role:
|
||||||
@@ -87,12 +93,18 @@ let
|
|||||||
roleServiceConfigs = builtins.map (
|
roleServiceConfigs = builtins.map (
|
||||||
role: serviceConfig.roles.${role}.config or { }
|
role: serviceConfig.roles.${role}.config or { }
|
||||||
) inverseRoles.${machineName} or [ ];
|
) inverseRoles.${machineName} or [ ];
|
||||||
|
dbg = v: lib.traceSeq v v;
|
||||||
|
|
||||||
|
customImports = map (s: "${directory}/${s}") (
|
||||||
|
globalImports ++ machineImports ++ roleServiceImports
|
||||||
|
);
|
||||||
in
|
in
|
||||||
|
|
||||||
if isInService then
|
if isInService then
|
||||||
acc2
|
acc2
|
||||||
++ [
|
++ [
|
||||||
{
|
{
|
||||||
imports = [ clan-core.clanModules.${moduleName} ] ++ roleModules;
|
imports = dbg ([ clan-core.clanModules.${moduleName} ] ++ roleModules ++ customImports);
|
||||||
config.clan.${moduleName} = lib.mkMerge (
|
config.clan.${moduleName} = lib.mkMerge (
|
||||||
[
|
[
|
||||||
globalConfig
|
globalConfig
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ let
|
|||||||
default = { };
|
default = { };
|
||||||
type = t.attrsOf t.anything;
|
type = t.attrsOf t.anything;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
importsOption = lib.mkOption {
|
||||||
|
default = [ ];
|
||||||
|
type = t.listOf t.str;
|
||||||
|
# apply = map (pathOrString: "${pathOrString}");
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@@ -76,10 +82,16 @@ in
|
|||||||
t.attrsOf (
|
t.attrsOf (
|
||||||
t.submodule {
|
t.submodule {
|
||||||
options.meta = metaOptions;
|
options.meta = metaOptions;
|
||||||
|
options.imports = importsOption;
|
||||||
options.config = moduleConfig;
|
options.config = moduleConfig;
|
||||||
options.machines = lib.mkOption {
|
options.machines = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = t.attrsOf (t.submodule { options.config = moduleConfig; });
|
type = t.attrsOf (
|
||||||
|
t.submodule {
|
||||||
|
options.imports = importsOption;
|
||||||
|
options.config = moduleConfig;
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
options.roles = lib.mkOption {
|
options.roles = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
@@ -95,6 +107,7 @@ in
|
|||||||
type = t.listOf tagRef;
|
type = t.listOf tagRef;
|
||||||
};
|
};
|
||||||
options.config = moduleConfig;
|
options.config = moduleConfig;
|
||||||
|
options.imports = importsOption;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user