output: allow to have host defined in subdirectory

This commit is contained in:
Wroclaw 2024-08-03 22:15:32 +02:00
parent 78ab704ca3
commit f4772d075a

View file

@ -22,22 +22,22 @@ self = {
filePaths = lib.pipe ./hosts [ filePaths = lib.pipe ./hosts [
builtins.readDir builtins.readDir
( lib.filterAttrs (name: type: ( lib.filterAttrs (name: type:
# filter out non-nix files ( # regular .nix files
type == "regular" (type == "regular" && lib.hasSuffix ".nix" name)
# filter out files that don't end in .nix || # directories that contain a default.nix file
&& lib.hasSuffix ".nix" name (type == "directory" && builtins.pathExists "${./hosts}/${name}/default.nix")
)
# filter out files that start with . # filter out files that start with .
&& !lib.hasPrefix "." name && !lib.hasPrefix "." name
)) ))
(lib.mapAttrsToList (name: _: name))
]; ];
nixosSystem = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix"; nixosSystem = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix";
in in
# mapped list of nix file paths to attrSet with initialized NixOS configurations, # mapped list of nix file paths to attrSet with initialized NixOS configurations,
# whose names are derived from file names # whose names are derived from file names
lib.pipe filePaths [ lib.pipe filePaths [
(builtins.map (name: { (builtins.mapAttrs (name: type: {
name = builtins.substring 0 (builtins.stringLength name - 4) name; name = if type == "directory" then name else builtins.substring 0 (builtins.stringLength name - 4) name;
value = nixosSystem { value = nixosSystem {
inherit lib; inherit lib;
modules = [ modules = [
@ -53,6 +53,7 @@ self = {
specialArgs = { inherit self inputs; }; specialArgs = { inherit self inputs; };
}; };
})) }))
builtins.attrValues
builtins.listToAttrs builtins.listToAttrs
]; ];
}; };