Merge pull request 'Inventory improvements' (#2113) from hsjobeki/clan-core:hsjobeki-main into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2113
This commit is contained in:
@@ -26,19 +26,19 @@
|
||||
},
|
||||
"roles": {
|
||||
"default": {
|
||||
"imports": [],
|
||||
"extraModules": [],
|
||||
"machines": ["test-inventory-machine"],
|
||||
"tags": []
|
||||
}
|
||||
},
|
||||
"config": {},
|
||||
"imports": [],
|
||||
"extraModules": [],
|
||||
"machines": {
|
||||
"test-inventory-machine": {
|
||||
"config": {
|
||||
"packages": ["zed-editor"]
|
||||
},
|
||||
"imports": []
|
||||
"extraModules": []
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -51,19 +51,19 @@
|
||||
"roles": {
|
||||
"default": {
|
||||
"config": {},
|
||||
"imports": [],
|
||||
"extraModules": [],
|
||||
"machines": ["test-inventory-machine"],
|
||||
"tags": []
|
||||
}
|
||||
},
|
||||
"config": {},
|
||||
"imports": [],
|
||||
"extraModules": [],
|
||||
"machines": {
|
||||
"test-inventory-machine": {
|
||||
"config": {
|
||||
"packages": ["chromium"]
|
||||
},
|
||||
"imports": []
|
||||
"extraModules": []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,19 +78,19 @@
|
||||
"roles": {
|
||||
"default": {
|
||||
"config": {},
|
||||
"imports": [],
|
||||
"extraModules": [],
|
||||
"machines": ["test-inventory-machine"],
|
||||
"tags": []
|
||||
}
|
||||
},
|
||||
"config": {},
|
||||
"imports": [],
|
||||
"extraModules": [],
|
||||
"machines": {
|
||||
"test-inventory-machine": {
|
||||
"config": {
|
||||
"device": "/dev/null"
|
||||
},
|
||||
"imports": []
|
||||
"extraModules": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +223,14 @@ in
|
||||
imports = [
|
||||
# Merge the inventory file
|
||||
{ inventory = inventoryLoaded; }
|
||||
# TODO: Figure out why this causes infinite recursion
|
||||
{
|
||||
inventory.machines = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (
|
||||
builtins.mapAttrs (_n: _v: { }) (
|
||||
(lib.filterAttrs (_: t: t == "directory") (builtins.readDir "${directory}/machines"))
|
||||
)
|
||||
);
|
||||
}
|
||||
# Merge the meta attributes from the buildClan function
|
||||
{ inventory.meta = if config.meta != null then config.meta else { }; }
|
||||
];
|
||||
|
||||
@@ -111,7 +111,10 @@ in
|
||||
in
|
||||
{
|
||||
expr = builtins.attrNames result.nixosConfigurations;
|
||||
expected = [ "test-inventory-machine" ];
|
||||
expected = [
|
||||
"test-backup"
|
||||
"test-inventory-machine"
|
||||
];
|
||||
};
|
||||
|
||||
test_buildClan_all_machines =
|
||||
|
||||
@@ -145,7 +145,7 @@ let
|
||||
builtins.map (role: serviceConfig.roles.${role}.config or { }) inverseRoles.${machineName} or [ ]
|
||||
);
|
||||
|
||||
customImports = map (s: "${directory}/${s}") (
|
||||
customImports = map (s: if builtins.typeOf s == "string" then "${directory}/${s}" else s) (
|
||||
globalImports ++ machineImports ++ roleServiceImports
|
||||
);
|
||||
in
|
||||
|
||||
@@ -33,13 +33,15 @@ let
|
||||
type = types.attrsOf types.anything;
|
||||
};
|
||||
|
||||
importsOption = lib.mkOption {
|
||||
extraModulesOption = lib.mkOption {
|
||||
description = ''
|
||||
List of imported '.nix' files.
|
||||
List of imported '.nix' expressions.
|
||||
|
||||
Each filename must be a string and is interpreted relative to the 'directory' passed to buildClan.
|
||||
Strings are interpreted relative to the 'directory' passed to buildClan.
|
||||
The import only happens if the machine is part of the service or role.
|
||||
|
||||
Other types are passed through to the nixos configuration.
|
||||
|
||||
## Example
|
||||
|
||||
To import the `special.nix` file
|
||||
@@ -55,13 +57,18 @@ let
|
||||
|
||||
```nix
|
||||
{
|
||||
imports = [ "modules/special.nix" ];
|
||||
extraModules = [ "modules/special.nix" ];
|
||||
}
|
||||
```
|
||||
|
||||
'';
|
||||
default = [ ];
|
||||
type = types.listOf types.str;
|
||||
type = types.listOf (
|
||||
types.oneOf [
|
||||
types.str
|
||||
types.anything
|
||||
]
|
||||
);
|
||||
};
|
||||
in
|
||||
{
|
||||
@@ -113,13 +120,13 @@ in
|
||||
{ name, ... }:
|
||||
{
|
||||
options.meta = metaOptionsWith name;
|
||||
options.imports = importsOption;
|
||||
options.extraModules = extraModulesOption;
|
||||
options.config = moduleConfig;
|
||||
options.machines = lib.mkOption {
|
||||
default = { };
|
||||
type = types.attrsOf (
|
||||
types.submodule {
|
||||
options.imports = importsOption;
|
||||
options.extraModules = extraModulesOption;
|
||||
options.config = moduleConfig;
|
||||
}
|
||||
);
|
||||
@@ -138,7 +145,7 @@ in
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
options.config = moduleConfig;
|
||||
options.imports = importsOption;
|
||||
options.extraModules = extraModulesOption;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user