-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
rustPlatform.buildRustPackage: support finalAttrs
style
#194475
base: master
Are you sure you want to change the base?
Conversation
aa4aa88
to
95a98c9
Compare
95a98c9
to
a8e675e
Compare
I came to this from #107070 and I must say that the fact that I can actually see and fix the |
a8e675e
to
9e66b79
Compare
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.
Hey, I'm totally in favor of this PR, but the way it's written makes it extremely difficult to review!
Could you please search-and-replace finalAttrs
with args
and previousAttrs
with args
? That alone will cut the size of the diff in half.
Then please add a let args = { src = args.src or null; ... }
to rebind (shadow) args
. That will cut the diff down to only a dozen lines changed or so -- way easier to review.
Thanks,
"checkInputs" "installCheckInputs" | ||
"__darwinAllowLocalNetworking" | ||
"__impureHostDeps" "__propagatedImpureHostDeps" | ||
"sandboxProfile" "propagatedSandboxProfile"]) | ||
"sandboxProfile" "propagatedSandboxProfile" | ||
"intermediateArgs"] ++ (attrs.intermediateArgs or []))) |
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.
Could we pick a more descriptive name here? Once chosen, it's hard to change this.
The purpose of this is to indicate which attributes should not become part of the builder's environment. So we should pick a name that makes that purpose obvious to the reader without having to open make-derivation.nix
in order to figure it out. Something like removeFromBuilderEnv
or filterFromDerivation
or notEnvVars
or something else entirely.
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.
Good point, will go with removeFromBuilderEnv
for now 👍
-> !(args ? cargoSha256 && args.cargoSha256 != null) && !(args ? cargoHash && args.cargoHash != null) | ||
-> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set"; | ||
assert buildType == "release" || buildType == "debug"; | ||
let rustOverlay = |
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.
Technically an overlay is a list of overrides. This is just an override.
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.
According to the nixpkgs manual:
Overlays are Nix functions which accept two arguments, conventionally called self and super, and return a set of packages.
rustOverlay
doesn't fulfill the "set of packages" criterion, so using sth more vague seems sensible, will change 👍
src = finalAttrs.src or ""; | ||
srcs = finalAttrs.srcs or null; | ||
sourceRoot = finalAttrs.sourceRoot or null; | ||
unpackPhase = finalAttrs.unpackPhase or null; | ||
cargoUpdateHook = finalAttrs.cargoUpdateHook or ""; | ||
# Name for the vendored dependencies tarball |
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.
In the future, for big refactors like this, it would make them easier to review if you "rebuilt" the args
attrset up at the top of the file (taking values from finalAttrs
instead of args
of course). Then you could make tiny easy-to-approve changes to lines like this, simply inserting (argsRebuilt)
after inherit
.
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.
Yeah, you raise a good point here and in #194475 (review) above. I can rewrite it in the style you are suggesting here, as there are no existing review threads etc. that would be invalidated by this. WDYT?
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.
Your call. The cleanup in your d16ba39 was enough that I was able to get through the diff without losing track of what was going on.
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.
Ok, then I will leave it is as is for now (unless someone else objects) -- I ran into difficult-to-debug "infinite recursion" errors when trying to refactor this, which I like to avoid debugging unless necessary 😄
9e66b79
to
d16ba39
Compare
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.
+2 We should merge this. I'd like to use it in #204694 and elsewhere.
Ping @roberth (who introduced mkDerivation (finalAttrs:
) and @Ericson2314 (the build-support/rust
guru) to see if they have any objections.
This produced no post-eval changes on either OfBorg or my system (which has a lot of overlays) for x86+arm+powerpc full workstation, mips router-only. So I feel confident it won't break things. If it does you can blame me.
d16ba39
to
d28df4f
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/1607 |
Poke @roberth ^^ |
buildAndTestSubdir = previousAttrs.buildAndTestSubdir or null; | ||
|
||
cargoBuildType = | ||
assert buildType == "release" || buildType == "debug"; |
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.
Can we move the assserts after the inputs? thats a bit cleaner than inlining them.
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.
Due to the evaluation model of finalAttrs
, the assertions can not be kept in the place they were before. Citing from the PR description:
Asserts involving attributes from
finalAttrs
have to be "hidden" inside of values. Right now, I moved them to the respective attributes/variables; another option would be to put them into a dedicatedasserts
attribute, i.e.asserts = assert (all asserts here); "";
.
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.
Just small suggestions; already looks good.
"checkInputs" "installCheckInputs" | ||
"__darwinAllowLocalNetworking" | ||
"__impureHostDeps" "__propagatedImpureHostDeps" | ||
"sandboxProfile" "propagatedSandboxProfile"]) | ||
"sandboxProfile" "propagatedSandboxProfile" | ||
"removeFromBuilderEnv"] ++ (attrs.removeFromBuilderEnv or []))) |
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.
👍 👍
d0f22c7
to
172ee4d
Compare
172ee4d
to
fc094d7
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/1704 |
Resolved the conflict in master...jtojnar:nixpkgs:buildRustPackage-finalAttrs |
fc094d7
to
c7be0c0
Compare
pname = "difftastic"; | ||
version = "0.46.0"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "wilfred"; | ||
repo = pname; | ||
rev = version; | ||
repo = finalAttrs.pname; |
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.
repo = finalAttrs.pname; | |
repo = "difftastic"; |
this is a bit problematic because if someone appends something to pname like -unwrapped
than the download link silently breaks because of FODs.
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.
It's worse: it wouldn't even break for you but for someone else, because - having the output - you don't need to re-run the FOD.
D.R.Y: do repeat yourself ;)
c7be0c0
to
67d3965
Compare
This is useful to remove intermediate/temporary arguments used in `finalAttrs`-style derivations.
Co-authored-by: Sandro <sandro.jaeckel@gmail.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
67d3965
to
48e9de7
Compare
# TODO using previousAttrs here as we otherwise trigger rebuilds for all | ||
# FOD fetcher users as finalAttrs.postUnpack is prefixed below. | ||
postUnpack = previousAttrs.postUnpack or null; |
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.
Side effect of #221093. This is not ideal; I guess one solution would be to accept the rebuilds, but maybe there is a different approach here.
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.
Attributes with null
values are completely removed from the .drv
, so this doesn't look like a mass rebuild to me.
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.
Here is a concrete example:
With this PR in its current state (48e9de7) as well as before this PR (fe2ecaf):
$ nix-instantiate -A cargo
/nix/store/1977acij72524vy0c8ij19ng7nzrf6yv-cargo-1.68.2.drv
After applying this diff
diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix
index f8e1eef2e93..6ca8a730d59 100644
--- a/pkgs/build-support/rust/build-rust-package/default.nix
+++ b/pkgs/build-support/rust/build-rust-package/default.nix
@@ -58,7 +58,7 @@ let
unpackPhase = finalAttrs.unpackPhase or null;
# TODO using previousAttrs here as we otherwise trigger rebuilds for all
# FOD fetcher users as finalAttrs.postUnpack is prefixed below.
- postUnpack = previousAttrs.postUnpack or null;
+ postUnpack = finalAttrs.postUnpack or null;
cargoUpdateHook = finalAttrs.cargoUpdateHook or "";
# Name for the vendored dependencies tarball
name = finalAttrs.cargoDepsName or finalAttrs.name or "${finalAttrs.pname}-${finalAttrs.version}";
we get
$ nix-instantiate -A cargo
/nix/store/3msgx9jda9kc6hvfl7vgf9b8nsbm5g6y-cargo-1.68.2.drv
Diff:
$ nix-diff /nix/store/1977acij72524vy0c8ij19ng7nzrf6yv-cargo-1.68.2.drv /nix/store/3msgx9jda9kc6hvfl7vgf9b8nsbm5g6y-cargo-1.68.2.drv
- /nix/store/1977acij72524vy0c8ij19ng7nzrf6yv-cargo-1.68.2.drv:{out}
+ /nix/store/3msgx9jda9kc6hvfl7vgf9b8nsbm5g6y-cargo-1.68.2.drv:{out}
• The input derivation named `cargo` differs
- /nix/store/qcsj2rh9k0dgig555kb12vx6zrzsw2nr-cargo.drv:{out}
+ /nix/store/fmvz39xbarfgssly8j6lzjp5dcxpgwxb-cargo.drv:{out}
• The input derivation named `cargo-auditable-0.6.1` differs
- /nix/store/7gkiqcx8qigih6pzga18ps6w5dpv3n33-cargo-auditable-0.6.1.drv:{out}
+ /nix/store/lnxzsh3ij88gp0vzj0628p1dn4gd2irj-cargo-auditable-0.6.1.drv:{out}
• The input derivation named `cargo-auditable-0.6.1-vendor.tar.gz` differs
- /nix/store/n67n6kbyd0ch4v88wwra9fy57p6mr263-cargo-auditable-0.6.1-vendor.tar.gz.drv:{out}
+ /nix/store/wkvcmy569xq0lgwbfvismc7f1lwb8qhb-cargo-auditable-0.6.1-vendor.tar.gz.drv:{out}
• The environments do not match:
+ postUnpack=eval "$cargoDepsHook"
export RUST_LOG=
• Skipping environment comparison
• Skipping environment comparison
• Skipping environment comparison
Does that demonstrate the problem more clearly?
|
I think there are no fundamental blockers, but the code here is rather tricky as it is super easy to accidentally write sth that causes infinite recursions, see #194475 (comment). I hope to rebase it in the next days, but everyone is also welcome to take over this PR if they want to drive this. I stopped regularly rebasing this PR as I wanted to wait for the pkgs-modules Nixpkgs Architectore working group, but I just saw that it was shut down for now.
From my PoV, #288430 could be merged before this PR as it is useful as long as some Rust packages are not yet using the
It is the regular |
Having this feature would really make my life much easier. It would make this override that I use in bombon to add a passthru SBOM to a Rust derivation much simpler: https://github.com/nikstur/bombon/blob/main/nix/passthru-vendored.nix#L9 Also it would make it much easier to add a passthru |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-do-you-override-the-commit-rev-used-by-a-rust-package/47698/3 |
We should probably get to this, considering the |
Description of changes
This PR explores supporting the new
finalAttrs
derivation style forbuildRustPackage
, similar to what is suggested in #119942 (comment). It is basically an extended version of #179392, and in particular also would close #107070.A few notes:
This change should be entirely opt-in and cause no rebuilds.
This PR adds an ad-hoc way to prevent some attrs (called "intermediate args" here) to be passed to the underlying derivation call by specifying
removeFromBuilderEnv
. Another option would be to allow an arbitrary function (similar toapply
in the module system), but that might be too powerful/confusing. Also see rustPlatform.buildRustPackage: supportfinalAttrs
style #194475 (comment).Rust packages can be incrementally converted and then enjoy the benefits outlined in stdenv.mkDerivation: overlay style overridable recursive attributes #119942
As an example, I converted
difftastic
to the new style, such that changing its version is now much DRYer:Also note that
passthru.tests.version
then automatically points to the new package.The "overlay" in
buildRustPackage
has a few curiosities, i.e. we have to be careful to avoidinfinite recursion
errors:{ a ? "", ...}@finalAttrs
syntax. Even{...}@finalAttrs
causesinfinite recursion
.finalAttrs
have to be "hidden" inside of values. Right now, I moved them to the respective attributes/variables; another option would be to put them into a dedicatedasserts
attribute, i.e.asserts = assert (all asserts here); "";
.Maybe there are better solutions for these problems around, but they don't seem too terrible.
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes