From a8f97ac1ff53a438144a300ffc446fb9b603c328 Mon Sep 17 00:00:00 2001 From: Kleidi Bujari Date: Sun, 27 Sep 2026 19:09:22 -0700 Subject: [lib/importDir] create importDir as standalone function --- lib/importDir.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/importDir.nix diff --git a/lib/importDir.nix b/lib/importDir.nix new file mode 100644 index 0000000..794d3e7 --- /dev/null +++ b/lib/importDir.nix @@ -0,0 +1,44 @@ +{ lib, ... }: +let + inherit (builtins) + head + mapAttrs + match + readDir + ; + + inherit (lib) + mapAttrs' + filterAttrs + ; +in + +path: fn: +let + entries = readDir path; + + # Get paths to directories + onlyDirs = filterAttrs (_name: type: type == "directory") entries; + dirPaths = mapAttrs (name: type: { + path = path + "/${name}"; + inherit type; + }) onlyDirs; + + # Get paths to nix files, where the name is the basename of the file without the .nix extension + nixPaths = removeAttrs (mapAttrs' ( + name: type: + let + nixName = match "(.*)\\.nix" name; + in + { + name = if type == "directory" || nixName == null then "__junk" else (head nixName); + value = { + path = path + "/${name}"; + type = type; + }; + } + ) entries) [ "__junk" ]; + + combined = dirPaths // nixPaths; +in +fn combined -- cgit v1.3.1