lib.addMetaAttrs: use overrideAttrs when available#423615
lib.addMetaAttrs: use overrideAttrs when available#423615winterqt merged 1 commit intoNixOS:masterfrom
Conversation
|
One thing I wasn't sure about was how to cleanly get a |
There was a problem hiding this comment.
This technique is identical to that used in readTree, which has been serving me well in Discord's monorepo for over a year now. The only issue we have with readTree is the interaction with addMetaAttrs, which this PR fixes.
|
Was this change tested with other meta attrs? Like |
|
nix-repl> ((lib.addMetaAttrs {position = "meow";} pkgs.hello).overrideAttrs {a = 1;}).meta.position
"/home/winter/src/nixpkgs/pkgs/by-name/he/hello/package.nix:47"
nix-repl> ((lib.addMetaAttrs {license = "meow";} pkgs.hello).overrideAttrs {a = 1;}).meta.license
"meow"The way around this is to override the nix-repl> ((pkgs.hello.overrideAttrs {pos = "meow";})).meta.position
error:
… while evaluating the attribute 'meta.position'
at /home/winter/src/nixpkgs/pkgs/stdenv/generic/check-meta.nix:616:7:
615| // optionalAttrs (pos != null) {
616| position = pos.file + ":" + toString pos.line;
| ^
617| }
… while selecting 'file'
at /home/winter/src/nixpkgs/pkgs/stdenv/generic/check-meta.nix:616:22:
615| // optionalAttrs (pos != null) {
616| position = pos.file + ":" + toString pos.line;
| ^
617| }
error: expected a set but found a string: "meow" |
|
Removing backport, not sure I trust this to not be a breaking change out-of-tree, even if the dependence on it is of course incorrect. |
Previously, any subsequent change to a derivation after
an `addMetaAttrs` call would cause said attribute(s) to
be unconditionally reset back to their previous value(s):
nix-repl> ((oldPkgs.lib.lowPrio oldPkgs.hello).overrideAttrs {a = 1;}).meta.priority
error:
… while evaluating the attribute 'meta.priority'
at /nix/store/nxdiklm6dnf9pma1zg7srls2nzrykrjf-nixos/nixos/pkgs/stdenv/generic/make-derivation.nix:846:17:
845| inherit passthru overrideAttrs;
846| inherit meta;
| ^
847| }
error: attribute 'priority' missing
at «string»:1:67:
1| ((oldPkgs.lib.lowPrio oldPkgs.hello).overrideAttrs {a = 1;}).meta.priority
| ^
This change makes it so that this does not happen (unless, of
course, a subsequent override does affect those values):
nix-repl> ((newPkgs.lib.lowPrio oldPkgs.hello).overrideAttrs {a = 1;}).meta.priority
10
Fixes NixOS#323624.
11b3e20 to
2141b4e
Compare
|
Rebased for posterity/the hell of it. |
|
I'm not sure I like that the changed package count is >0, and that it went up from July. |
Here's the link to the specifics.
|
|
Of these, only |
|
Thanks! I’ll take a look at this tomorrow, though it looks like all of these are just making the env more correct! (Besides the scary one, of course.) (I saw the changed attribute names @philiptaron, but how did you get the nix-diff output?) |
I did a
Then I looked at them. |
|
OK, "paths": [
"/nix/store/cngwgf1q9jxx6k5dgk9j91kvpqzymdj2-v4l-utils-1.30.1-dev",
"/nix/store/cngwgf1q9jxx6k5dgk9j91kvpqzymdj2-v4l-utils-1.30.1-dev"
],
- "priority": 5
+ "priority": 10
},
{
"paths": [
"/nix/store/b5r4kj91isan88a0sff3y5ax26vpxzsf-libxau-1.0.12-dev", |
philiptaron
left a comment
There was a problem hiding this comment.
After diving into rebuilds, I believe this is just straightforward goodness.
I see this in my diff (expectedly), but doing a |
|
I don't see the |
|
I’m on the latest version of Lix. I guess this is something that differs between them! |
|
This broke |
|
The reason it broke tesseract is that tesseract is using |
Previously, any subsequent change to a derivation after an
addMetaAttrscall would cause said attribute(s) to be unconditionally reset back to their previous value(s):This change makes it so that this does not happen (unless, of course, a subsequent override does affect those values):
Fixes #323624.
Note: This work was funded by Antithesis.
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.