From ef34f35e454a9c035b7edbeebea23f529f86e296 Mon Sep 17 00:00:00 2001 From: Eman Resu Date: Wed, 12 Aug 2026 14:51:50 -0400 Subject: [PATCH] lib.fileset: start by recursing into the initial element This is guaranteed to be safe. The tree can be a simple string if the fileset is the same as the root, but the `or` takes care of that. In the `or` case, the tree is guaranteed to fail the isAttrs check, and so even though the index is invalid, it won't matter. --- lib/fileset/internal.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix index 704fd10835da..3d32c5fc3ef7 100644 --- a/lib/fileset/internal.nix +++ b/lib/fileset/internal.nix @@ -563,7 +563,12 @@ rec { # or a string ("directory" or "regular", etc.) in which case it's included localTree != null; in - recurse 0 tree; + # Start by recursing into the first element. This is guaranteed to be + # safe. components will never be empty (builtins.split can't make an + # empty list). Tree can be something other than an attrset, but if so, + # the isAttrs check will fail when being passed `or tree`, and the index + # being ahead doesn't matter. + recurse 2 (tree.${head components} or tree); # Filter suited when there's no files empty = _: _: false;