mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
lib.attrsets.filterAttrs: Add tips / guidance (#428330)
This commit is contained in:
@@ -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.
|
||||
|
||||
<!-- TIP -->
|
||||
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.)
|
||||
|
||||
<!-- TIP -->
|
||||
`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
|
||||
|
||||
Reference in New Issue
Block a user