clan: revert imports.nix and wait till tuesday
This commit is contained in:
@@ -18,16 +18,6 @@ Every folder `machines/{machineName}` will be registered automatically as a Clan
|
||||
- [x] `machines/{machineName}/disko.nix` Automatically loaded, for further information see the [disko docs](https://github.com/nix-community/disko/blob/master/docs/quickstart.md).
|
||||
|
||||
|
||||
## Automatic Imports
|
||||
|
||||
The `buildClan` function will automatically import modules if a directory named `<CLAN_ROOT>/imports` exists within the Clan. Below are the conditions for automatically importing `clanModules`:
|
||||
|
||||
- **Clan Modules**: Modules located in `<CLAN_ROOT>/imports/inventory` will be automatically imported. Note that only inventory-compatible modules can be used in this location. To be compatible, a module must contain a `roles` folder.
|
||||
|
||||
- **Adding a Module**: To add a module, such as `mymodule`, create a dedicated directory at `<CLAN_ROOT>/imports/inventory/mymodule`, ensuring that it includes a `roles` folder.
|
||||
|
||||
For further details on creating Clan modules, please refer to the [Authoring Clan Modules](../clanmodules/index.md) section.
|
||||
|
||||
|
||||
## Manual declaration
|
||||
|
||||
|
||||
@@ -35,6 +35,5 @@ eval {
|
||||
rest
|
||||
# implementation
|
||||
./module.nix
|
||||
./imports.nix
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
##################################
|
||||
# #
|
||||
# Handle the "imports" directory #
|
||||
# #
|
||||
##################################
|
||||
|
||||
let
|
||||
inherit (config)
|
||||
directory
|
||||
;
|
||||
|
||||
# Check if the imports directory exists
|
||||
# If it does, check if the files in the directory are allowed
|
||||
importsDir =
|
||||
if builtins.pathExists "${directory}/imports" then
|
||||
(
|
||||
let
|
||||
allowedFiles = [
|
||||
"inventory"
|
||||
];
|
||||
invalidImports = lib.filter (name: !(lib.elem name allowedFiles)) (
|
||||
builtins.attrNames (builtins.readDir "${directory}/imports")
|
||||
);
|
||||
in
|
||||
if invalidImports != [ ] then
|
||||
builtins.throw ''
|
||||
Invalid file imports/{${lib.concatStringsSep ", " invalidImports}}.
|
||||
Allowed are imports/{${lib.concatStringsSep ", " allowedFiles}}
|
||||
''
|
||||
else
|
||||
"${directory}/imports"
|
||||
)
|
||||
else
|
||||
"${directory}/imports";
|
||||
|
||||
# Get the directory names in the inventory/imports directory
|
||||
inventoryImportNames =
|
||||
if builtins.pathExists "${importsDir}/inventory" then
|
||||
let
|
||||
inventoryEntries = builtins.readDir "${importsDir}/inventory";
|
||||
invalidFiles = builtins.attrNames (lib.filterAttrs (_: type: type == "regular") inventoryEntries);
|
||||
in
|
||||
if invalidFiles != [ ] then
|
||||
builtins.throw ''
|
||||
Invalid file(s) in imports/inventory/{${lib.concatStringsSep ", " invalidFiles}}
|
||||
Only directories are allowed.
|
||||
''
|
||||
else
|
||||
builtins.attrNames (lib.filterAttrs (_: type: type == "directory") inventoryEntries)
|
||||
else
|
||||
[ ];
|
||||
|
||||
# Check if the roles directory exists in each inventory import
|
||||
inventoryImportAttrsetWithCheck = lib.genAttrs inventoryImportNames (
|
||||
name:
|
||||
let
|
||||
rolesDir = "${directory}/imports/inventory/${name}/roles";
|
||||
in
|
||||
if builtins.pathExists rolesDir then
|
||||
rolesDir
|
||||
else
|
||||
builtins.throw "The module ${name} is not inventory compatible because the roles directory does not exist at ${rolesDir}"
|
||||
);
|
||||
in
|
||||
{
|
||||
inventory.modules = inventoryImportAttrsetWithCheck;
|
||||
}
|
||||
Reference in New Issue
Block a user