summary refs log tree commit diff
path: root/lib/filesystem.nix
diff options
context:
space:
mode:
authorFarid Zakaria <fmzakari@google.com>2020-10-19 14:33:52 -0700
committerFarid Zakaria <fmzakari@google.com>2020-10-19 16:42:21 -0700
commit5f1d1bc57e8071472780e8cb14f6306225a921f1 (patch)
tree725ea43ae535b506c8ffe6f1e949dd1271ece092 /lib/filesystem.nix
parent8b4d70ca94e3ebb959d8737925d2958ea6576c81 (diff)
downloadnixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.tar
nixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.tar.gz
nixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.tar.bz2
nixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.tar.lz
nixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.tar.xz
nixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.tar.zst
nixpkgs-5f1d1bc57e8071472780e8cb14f6306225a921f1.zip
lib: Add readTree function to filesystem
Add a friendly function to easily return a flattened list of files
within a directory.

This is useful if you want to easily iterate or concatSep the list of
files all found within a directory.
(i.e. when constructing Java's CLASSPATH)

Style improvements

Co-authored-by: Silvan Mosberger <github@infinisil.com>
Diffstat (limited to 'lib/filesystem.nix')
-rw-r--r--lib/filesystem.nix12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/filesystem.nix b/lib/filesystem.nix
index fc35a1a72c6..0a1275e547c 100644
--- a/lib/filesystem.nix
+++ b/lib/filesystem.nix
@@ -42,4 +42,16 @@
               type = (builtins.readDir parent).${base} or null;
           in file == /. || type == "directory";
     in go (if isDir then file else parent);
+
+
+  # listFilesRecursive: Path -> [ Path ]
+  #
+  # Given a directory, return a flattened list of all files within it recursively.
+  listFilesRecursive = dir: lib.flatten (lib.mapAttrsToList (name: type:
+    if type == "directory" then
+      lib.filesystem.listFilesRecursive (dir + "/${name}")
+    else
+      dir + "/${name}"
+  ) (builtins.readDir dir));
+
 }