You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I understand the rationale for why readTree prefers overrideAttrs when available - it avoids inadvertently changing a derivation by merging arbitrary values on top of it, while it is much safer to leverage passthru which avoids any inadvertent cache-busting.
Unfortunately, this ends up causing some very non-intuitive behavior. Anything that is merged on top of a derivation using simple tools like // gets silently discarded, which can be very surprising.
For a contrived example, consider a readTree node that looks like this:
# customCowsay.nix{pkgs, ...}:
pkgs.cowsay//{hello="here is a value that I am very explicitly merging on top";}
Under readTree, if I try to reference customCowsay.hello, I will get an error that the attribute hello doesn't exist. How can that be? I most certainly added it! It takes a person well versed in nix, and willing to go hunting, to understand that this problem is that our value is getting transformed by calling overrideAttrs.
For a more concrete example, consider lib.hiPrio in nixpkgs. It sets meta.priority on an attrset using simple merging. So if we try to do something such as:
This was originally added in https://cl.tvl.fyi/5186 - basically so that other people who call .overrideAttrs wouldn't cause problems for the readTree-added attributes. lol, lmao, etc.
Opened up NixOS/nixpkgs#323624 over at nixpkgs, as on first glance it strikes me as reasonable that addMetaAttrs should try to use overrideAttrs if available.
If a readTree node is a derivation, readTree will always call
overrideAttrs
on it, which will silently discard information.I think I understand the rationale for why readTree prefers
overrideAttrs
when available - it avoids inadvertently changing a derivation by merging arbitrary values on top of it, while it is much safer to leveragepassthru
which avoids any inadvertent cache-busting.Unfortunately, this ends up causing some very non-intuitive behavior. Anything that is merged on top of a derivation using simple tools like
//
gets silently discarded, which can be very surprising.For a contrived example, consider a readTree node that looks like this:
Under readTree, if I try to reference
customCowsay.hello
, I will get an error that the attributehello
doesn't exist. How can that be? I most certainly added it! It takes a person well versed in nix, and willing to go hunting, to understand that this problem is that our value is getting transformed by callingoverrideAttrs
.For a more concrete example, consider
lib.hiPrio
in nixpkgs. It setsmeta.priority
on an attrset using simple merging. So if we try to do something such as:Then the priority will be lost.
The text was updated successfully, but these errors were encountered: