From ca59048a4242bf0741813794d805a153f5f95c2a Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:50:13 -0400 Subject: [PATCH] lib.filesystem.listFilesRecursive: only flatten once --- lib/filesystem.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/filesystem.nix b/lib/filesystem.nix index a950720602a7..afc4c2698291 100644 --- a/lib/filesystem.nix +++ b/lib/filesystem.nix @@ -239,16 +239,15 @@ in ``` */ listFilesRecursive = - dir: - lib.flatten ( - lib.mapAttrsToList ( - name: type: - if type == "directory" then - lib.filesystem.listFilesRecursive (dir + "/${name}") - else - dir + "/${name}" - ) (builtins.readDir dir) - ); + let + # We only flatten at the very end, as flatten is recursive. + internalFunc = + dir: + (lib.mapAttrsToList ( + name: type: if type == "directory" then internalFunc (dir + "/${name}") else dir + "/${name}" + ) (builtins.readDir dir)); + in + dir: lib.flatten (internalFunc dir); /** Transform a directory tree containing package files suitable for