Revert "buildClan: Add automatic inventory import directory"
This reverts commit 850eabb98c.
This introduces the name "inventory module" whereas we already use the
term clan modules everywhere else. I don't don't too many confusing
termologies in the codebase. Let's discuss this before adding it back.
This commit is contained in:
@@ -35,6 +35,5 @@ eval {
|
|||||||
rest
|
rest
|
||||||
# implementation
|
# implementation
|
||||||
./module.nix
|
./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;
|
|
||||||
}
|
|
||||||
@@ -167,7 +167,6 @@ let
|
|||||||
(builtins.fromJSON (builtins.readFile inventoryFile))
|
(builtins.fromJSON (builtins.readFile inventoryFile))
|
||||||
else
|
else
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
@@ -190,9 +189,7 @@ in
|
|||||||
inventory.machines = lib.mapAttrs (_n: _: { }) config.machines;
|
inventory.machines = lib.mapAttrs (_n: _: { }) config.machines;
|
||||||
}
|
}
|
||||||
# Merge the meta attributes from the buildClan function
|
# Merge the meta attributes from the buildClan function
|
||||||
{
|
{ inventory.modules = clan-core.clanModules; }
|
||||||
inventory.modules = clan-core.clanModules;
|
|
||||||
}
|
|
||||||
# config.inventory.meta <- config.meta
|
# config.inventory.meta <- config.meta
|
||||||
{ inventory.meta = config.meta; }
|
{ inventory.meta = config.meta; }
|
||||||
# Set default for computed tags
|
# Set default for computed tags
|
||||||
|
|||||||
Reference in New Issue
Block a user