-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix getAttrPos after mapAttrs #13725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Does this fix #13166? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we're deciding that the attribute position is about the attribute name more so than its value.
Otherwise, the position should be on line 6
key: value: value
^
The chosen interpretation of the attribute position seems more useful, so I think it's the right choice.
Another way to look at it is that an attribute is a metadata-carrying one-item container, whose metadata does not change. Then mapAttrs
can be seen as a bunch of functional, pointwise attribute "updates".
As far as I understand the CI error, it’s caused by this line in nixpkgs. I don’t understand the underlying reasons for doing it this way, nor whether my PR is unacceptable and breaks nixpkgs. If this change is indeed valid, I’m not entirely sure how I should proceed to update nixpkgs and Nix. |
I've researched the issue a bit, it seems to me that the problem is not in the sequence of applying the // operator, but in the fact that the filterAttrs function calls removeAttrs, which has a similar error as with mapAttrs, the position from the original attrset is not entered in this line(This should be the third parameter of emplace_back, since it is the 3rd parameter of the constructor Attr). Apparently this is not an isolated error as I thought, I'll try to run through all the builtin functions that interact with attrset in one way or another. |
This is, I believe, why it's |
Yes, it's because it's a derivation stability footgun.
Yeah, this whole mechanism definitely isn't a good one and is kind of a hack. Really you want to think about the way to write the position stuff as a nixpkgs level API question.
I think this is a correct read, it's a best effort position mechanism. There were likely serious performance considerations involved in how these decisions were made also, nix-re.pl implements positions on every type, but nix only does in attrsets themselves, functions, and attrset attributes. |
538d060
to
4824837
Compare
This is rather significant. If we decide this is the rule, other constructs should follow. Candidates:
Are we ok with these consequences? |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2025-08-20-nix-team-meeting-minutes-242-241/68245/1 |
Motivation
Fix position information loss in
mapAttrs
that breaksunsafeGetAttrPos
.Context
mapAttrs
wasn't preserving attribute positionsi.pos
)Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.