handle the special case of default.nix

This commit is contained in:
Chris Kruining 2025-04-24 23:20:17 +02:00
parent abdf88a717
commit 627510211c
Signed by: chris
SSH key fingerprint: SHA256:nG82MUfuVdRVyCKKWqhY+pCrbz9nbX6uzUns4RKa1Pg

View file

@ -38,9 +38,14 @@ in rec
readNixosModules = dir: fn: filterAttrs (name: value: value != null && !(hasPrefix "_" name)) (listToAttrs (flatten (readDirRecursive fn dir "")));
readDirRecursive = fn: root: dir: mapAttrsToList (name: type:
if type == "directory"
if type == "directory" && pathExists "${root}/${dir}/${name}/default.nix"
then [
(nameValuePair "${replaceStrings ["/"] ["_"] (removePrefix "/" dir)}_${name}" (fn "${root}/${dir}/${name}/default.nix"))
(readDirRecursive fn root "${dir}/${name}")
]
else if type == "directory"
then readDirRecursive fn root "${dir}/${name}"
else if type == "regular" && hasSuffix ".nix" name
else if type == "regular" && name != "default.nix" && hasSuffix ".nix" name
then nameValuePair "${replaceStrings ["/"] ["_"] (removePrefix "/" dir)}_${removeSuffix ".nix" name}" (fn "${root}/${dir}/${name}")
else nameValuePair "" null
) (readDir "${root}/${dir}");