1
1
forked from extern/flakelight

Extend autoloading to include importable directories

Now if a dir is treated as an attrset, subdirs with `default.nix` will
be loaded as attrs.
This commit is contained in:
Archit Gupta 2024-01-14 01:24:52 -08:00
parent cf3a2e5496
commit ec343ae967

View File

@ -100,12 +100,15 @@ let
(pipe (readDir path) [
attrNames
(filter (s: s != "default.nix"))
(filter (hasSuffix ".nix"))
(filter (s: (hasSuffix ".nix" s)
|| pathExists (path + "/${s}/default.nix")))
(map (removeSuffix ".nix"))
(map (removePrefix "_"))
])
(p: import (path + (if pathExists
(path + "/_${p}.nix") then "/_${p}.nix" else "/${p}.nix")));
(p: import (path +
(if pathExists (path + "/_${p}.nix") then "/_${p}.nix"
else if pathExists (path + "/${p}.nix") then "/${p}.nix"
else "/${p}")));
autoImport = dir: name:
if isList name