From 77c2981a7d404f2c59e7017d124156285463e247 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 25 Jul 2025 15:18:09 +0200 Subject: [PATCH] lib.attrsets.filterAttrs: Add tips to doc --- lib/attrsets.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 8fac72e741c7..124c22a885e1 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -633,6 +633,16 @@ rec { : Predicate taking an attribute name and an attribute value, which returns `true` to include the attribute, or `false` to exclude the attribute. + + If possible, decide on `name` first and on `value` only if necessary. + This avoids evaluating the value if the name is already enough, making it possible, potentially, to have the argument reference the return value. + (Depending on context, that could still be considered a self reference by users; a common pattern in Nix.) + + + `filterAttrs` is occasionally the cause of infinite recursion in configuration systems that allow self-references. + To support the widest range of user-provided logic, perform the `filterAttrs` call as late as possible. + Typically that's right before using it in a derivation, as opposed to an implicit conversion whose result is accessible to the user's expressions. + `set` : The attribute set to filter