diff options
| author | Kleidi Bujari <mail@4kb.net> | 2026-10-24 22:52:35 -0700 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2026-10-24 22:59:09 -0700 |
| commit | 48c8a4145c5a73874797a6de3f05ce584b1d1798 (patch) | |
| tree | bd4c627e8c8944fb7082b7a9982e8d3677c2a2c4 /lib/importDir.nix | |
| parent | 1a181be93f37a94b347b2f5f97a1fef57e11cf89 (diff) | |
| parent | 27db59cac4f3c3e7a1e4187a5f56d4ec61895c5a (diff) | |
| download | depot-48c8a4145c5a73874797a6de3f05ce584b1d1798.tar.gz depot-48c8a4145c5a73874797a6de3f05ce584b1d1798.tar.bz2 depot-48c8a4145c5a73874797a6de3f05ce584b1d1798.zip | |
Diffstat (limited to 'lib/importDir.nix')
| -rw-r--r-- | lib/importDir.nix | 44 |
1 files changed, 44 insertions, 0 deletions
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 |
