summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2026-09-27 19:09:22 -0700
committerKleidi Bujari <mail@4kb.net>2026-09-27 19:09:22 -0700
commita8f97ac1ff53a438144a300ffc446fb9b603c328 (patch)
treefdebf6a36e727d309817f135f8778ce6f33be300
parent2c0754da998f09c4ea21f9158fd9fafacf11a796 (diff)
downloaddepot-a8f97ac1ff53a438144a300ffc446fb9b603c328.tar.gz
depot-a8f97ac1ff53a438144a300ffc446fb9b603c328.tar.bz2
depot-a8f97ac1ff53a438144a300ffc446fb9b603c328.zip
[lib/importDir] create importDir as standalone function
-rw-r--r--lib/importDir.nix44
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