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": {
|
"roles": {
|
||||||
"default": {
|
"default": {
|
||||||
"imports": [],
|
"extraModules": [],
|
||||||
"machines": ["test-inventory-machine"],
|
"machines": ["test-inventory-machine"],
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {},
|
"config": {},
|
||||||
"imports": [],
|
"extraModules": [],
|
||||||
"machines": {
|
"machines": {
|
||||||
"test-inventory-machine": {
|
"test-inventory-machine": {
|
||||||
"config": {
|
"config": {
|
||||||
"packages": ["zed-editor"]
|
"packages": ["zed-editor"]
|
||||||
},
|
},
|
||||||
"imports": []
|
"extraModules": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -51,19 +51,19 @@
|
|||||||
"roles": {
|
"roles": {
|
||||||
"default": {
|
"default": {
|
||||||
"config": {},
|
"config": {},
|
||||||
"imports": [],
|
"extraModules": [],
|
||||||
"machines": ["test-inventory-machine"],
|
"machines": ["test-inventory-machine"],
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {},
|
"config": {},
|
||||||
"imports": [],
|
"extraModules": [],
|
||||||
"machines": {
|
"machines": {
|
||||||
"test-inventory-machine": {
|
"test-inventory-machine": {
|
||||||
"config": {
|
"config": {
|
||||||
"packages": ["chromium"]
|
"packages": ["chromium"]
|
||||||
},
|
},
|
||||||
"imports": []
|
"extraModules": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,19 +78,19 @@
|
|||||||
"roles": {
|
"roles": {
|
||||||
"default": {
|
"default": {
|
||||||
"config": {},
|
"config": {},
|
||||||
"imports": [],
|
"extraModules": [],
|
||||||
"machines": ["test-inventory-machine"],
|
"machines": ["test-inventory-machine"],
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {},
|
"config": {},
|
||||||
"imports": [],
|
"extraModules": [],
|
||||||
"machines": {
|
"machines": {
|
||||||
"test-inventory-machine": {
|
"test-inventory-machine": {
|
||||||
"config": {
|
"config": {
|
||||||
"device": "/dev/null"
|
"device": "/dev/null"
|
||||||
},
|
},
|
||||||
"imports": []
|
"extraModules": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,6 +223,14 @@ in
|
|||||||
imports = [
|
imports = [
|
||||||
# Merge the inventory file
|
# Merge the inventory file
|
||||||
{ inventory = inventoryLoaded; }
|
{ 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
|
# Merge the meta attributes from the buildClan function
|
||||||
{ inventory.meta = if config.meta != null then config.meta else { }; }
|
{ inventory.meta = if config.meta != null then config.meta else { }; }
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -111,7 +111,10 @@ in
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
expr = builtins.attrNames result.nixosConfigurations;
|
expr = builtins.attrNames result.nixosConfigurations;
|
||||||
expected = [ "test-inventory-machine" ];
|
expected = [
|
||||||
|
"test-backup"
|
||||||
|
"test-inventory-machine"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
test_buildClan_all_machines =
|
test_buildClan_all_machines =
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ let
|
|||||||
builtins.map (role: serviceConfig.roles.${role}.config or { }) inverseRoles.${machineName} or [ ]
|
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
|
globalImports ++ machineImports ++ roleServiceImports
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -33,13 +33,15 @@ let
|
|||||||
type = types.attrsOf types.anything;
|
type = types.attrsOf types.anything;
|
||||||
};
|
};
|
||||||
|
|
||||||
importsOption = lib.mkOption {
|
extraModulesOption = lib.mkOption {
|
||||||
description = ''
|
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.
|
The import only happens if the machine is part of the service or role.
|
||||||
|
|
||||||
|
Other types are passed through to the nixos configuration.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
To import the `special.nix` file
|
To import the `special.nix` file
|
||||||
@@ -55,13 +57,18 @@ let
|
|||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
imports = [ "modules/special.nix" ];
|
extraModules = [ "modules/special.nix" ];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
'';
|
'';
|
||||||
default = [ ];
|
default = [ ];
|
||||||
type = types.listOf types.str;
|
type = types.listOf (
|
||||||
|
types.oneOf [
|
||||||
|
types.str
|
||||||
|
types.anything
|
||||||
|
]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -113,13 +120,13 @@ in
|
|||||||
{ name, ... }:
|
{ name, ... }:
|
||||||
{
|
{
|
||||||
options.meta = metaOptionsWith name;
|
options.meta = metaOptionsWith name;
|
||||||
options.imports = importsOption;
|
options.extraModules = extraModulesOption;
|
||||||
options.config = moduleConfig;
|
options.config = moduleConfig;
|
||||||
options.machines = lib.mkOption {
|
options.machines = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = types.attrsOf (
|
type = types.attrsOf (
|
||||||
types.submodule {
|
types.submodule {
|
||||||
options.imports = importsOption;
|
options.extraModules = extraModulesOption;
|
||||||
options.config = moduleConfig;
|
options.config = moduleConfig;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -138,7 +145,7 @@ in
|
|||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
};
|
};
|
||||||
options.config = moduleConfig;
|
options.config = moduleConfig;
|
||||||
options.imports = importsOption;
|
options.extraModules = extraModulesOption;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user