-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
buildGoModule: Fix overriding with overlay-style stdenv #225051
buildGoModule: Fix overriding with overlay-style stdenv #225051
Conversation
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 may not be a breaking change but I think we're to close to branch off for this so I'm a very strongly against including it in 23.05.
Also, I am planning to make a few changes to buildGoModule
after the branch, e.g. drop vendorSha256
and only have vendorHash
, it'll be easier and make this PR simpler if that happens first.
cc @NixOS/golang
Agree. Should I drop change to the the release note? I place them there just because the new release note hasn't come out yet. |
Would it be okay to just remove those |
Fine to leave them there for now, can be moved once the new release note is created after branch off.
Maybe, have to give it some thought first. Also, I'd appreciate it if you would revert all of the unrelated formatting changes, it makes the diff much harder to review. |
eeb5844
to
0e87a61
Compare
It turns out that the indentation difference is not just caused by Even then, I managed to make them align by making reasonable adjustment to the original expression (mainly by simplifying the The last commit contains the actual change. The relation between the original implementation and the new implementation can be seen from the diff. The expected attributes are organized at the beginning of the expression, and the corresponding comment documentation are prefixed with |
0e87a61
to
bd74d74
Compare
@ShamrockLee I'm switching this back to draft as it isn't going to be merged until after branch off. |
Still needs more testing but I've opened a PR to (mostly) get rid of vendorSha256. |
Go packages built with this buildGoModule implementation seems to take noticable longer to evaluate. Not sure if it also happens to #171586. How can we benchmark the evaluation time? |
bd74d74
to
fee7aae
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.
Looks good overall! Well done for all the work.
# Canonicallize `overrideModAttrs` as an attribute overlay. | ||
# `passthru.overrideModAttrs` will be overridden | ||
# when users want to override `goModules`. | ||
overrideModAttrs = toExtension overrideModAttrs; |
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.
Since this is the only place that toExtension
is used, perhaps you'd like to put it inline here? It might make the diff a bit smaller..
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.
Quoting myself:
Since this is the only place that
toExtension
is used, perhaps you'd like to put it inline here? It might make the diff a bit smaller..
What do you think about this idea @ShamrockLee ?
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.
If this function works well, I plan to move it into lib.fixedPoints
, so I defined it separately.
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.
If this function works well, I plan to move it into
lib.fixedPoints
, so I defined it separately.
OK sounds like a good idea to me.
|
||
```sh | ||
cd path/to/nixpkgs | ||
nix-prefetch -E "{ sha256 }: ((import ./. { }).my-package.overrideAttrs (_: { vendorHash = sha256; })).go-modules" |
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.
nix-prefetch -E "{ sha256 }: ((import ./. { }).my-package.overrideAttrs (_: { vendorHash = sha256; })).go-modules" | |
nix-prefetch -E "{ hash }: ((import ./. { }).my-package.overrideAttrs (_: { vendorHash = hash; })).go-modules" |
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.
This is not supported by nix-prefetch. I changed it back.
115a1a8
to
7352540
Compare
@doronbehar Thank you for reviewing and giving feedback. I revised the Overriding |
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.
Looks much better!
1fcaf0d
to
8ca991e
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.
One last round I hope!
}; | ||
} | ||
); | ||
pet-vendored = pet-foo.overrideAttrs { vendorHash = 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.
This is a bit surprising, perhaps the paragraph above should mention why you set vendorHash = null;
? Or perhaps explain this here in a a comment? (I think I understood correctly this is because you set overrideModAttrs
...)
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.
venhorHash = null
is to prevent vendoring from the Nix side by goModules
. People set it because the source is "vendored" (contains the vendor
directory), and they would like to use such vendoring. For example, the Apptainer project provided vendored source tarballs in each release when the project was still known as Singularity.
If a user would like to use the goModules
vendoring instead of the upstream one, they would set deleteVendor = true
instead.
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.
venhorHash = null
is to prevent vendoring from the Nix side bygoModules
. People set it because the source is "vendored" (contains thevendor
directory), and they would like to use such vendoring. For example, the Apptainer project provided vendored source tarballs in each release when the project was still known as Singularity.If a user would like to use the
goModules
vendoring instead of the upstream one, they would setdeleteVendor = true
instead.
I'm sorry but I did not understand :). I'll write again what I wanted you to explain in a comment / what I felt is missing:
The purpose of this example is to demonstrate how to use overrideModAttrs
, but what is peculiar to me, is that you perform an additional overrideAttrs
of vendorHash = null;
. I don't understand how that is related to overrdeModAttrs
- if you set overrideModAttrs
do you have to also set vendorHash = null;
afterwards? If so, why (explain in a code comment)? If you don't have to set vendorHash = null;
afterwards, please remove that, and finish with:
in
pet-foo
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.
Sorry for causing the confusion.
In my imagination, the first overriding targeting goModules
might be buried somewhere inside the codebase, while another user made another overriding and set vendorHash = null
.
The purpose of this documentation is to avoid the conflicts between these overridings.
pet-vendored = pet-foo.overrideAttrs { vendorHash = null; }; | ||
in | ||
pet-vendored |
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.
Perhaps (hopefully it is still nixfmt correct):
pet-vendored = pet-foo.overrideAttrs { vendorHash = null; }; | |
in | |
pet-vendored | |
in | |
pet-foo.overrideAttrs { vendorHash = null; }; |
c931b65
to
85c6d07
Compare
let | ||
pet-foo = pkgs.overrideAttrs ( | ||
finalAttrs: previousAttrs: { | ||
passthru = previousAttrs.passthru // { | ||
overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs ( | ||
finalModAttrs: previousModAttrs: { | ||
# goModules-specific overriding goes here | ||
postBuild = '' | ||
# Here you have access to the `vendor` directory. | ||
substituteInPlace vendor/github.com/example/repo/file.go \ | ||
--replace-fail "panic(err)" "" | ||
''; | ||
} | ||
); | ||
}; | ||
} | ||
); | ||
pet-vendored = pet-foo.overrideAttrs { vendorHash = null; }; | ||
in | ||
pet-vendored |
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.
Sorry for causing the confusion.
No worries :).
In my imagination, the first overriding targeting
goModules
might be buried somewhere inside the codebase, while another user made another overriding and setvendorHash = null
.The purpose of this documentation is to avoid the conflicts between these overridings.
Hmm this is a bit complicated for at this point, so I'm still not sure I understand. Let's ask this: Why not:
let | |
pet-foo = pkgs.overrideAttrs ( | |
finalAttrs: previousAttrs: { | |
passthru = previousAttrs.passthru // { | |
overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs ( | |
finalModAttrs: previousModAttrs: { | |
# goModules-specific overriding goes here | |
postBuild = '' | |
# Here you have access to the `vendor` directory. | |
substituteInPlace vendor/github.com/example/repo/file.go \ | |
--replace-fail "panic(err)" "" | |
''; | |
} | |
); | |
}; | |
} | |
); | |
pet-vendored = pet-foo.overrideAttrs { vendorHash = null; }; | |
in | |
pet-vendored | |
let | |
pet-foo = pkgs.overrideAttrs ( | |
finalAttrs: previousAttrs: { | |
# TODO: Explain this? | |
vendorHash = null; | |
passthru = previousAttrs.passthru // { | |
overrideModAttrs = lib.composeExtensions previousAttrs.passthru.overrideModAttrs ( | |
finalModAttrs: previousModAttrs: { | |
# goModules-specific overriding goes here | |
postBuild = '' | |
# Here you have access to the `vendor` directory. | |
substituteInPlace vendor/github.com/example/repo/file.go \ | |
--replace-fail "panic(err)" "" | |
''; | |
} | |
); | |
}; | |
} | |
); | |
in | |
pet-foo |
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.
Let's avoid the confusion by removing vendorHash = null
and leaving it as a simple example demonstrating the correct overriding approach.
bea7e1a
to
1d618a3
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.
Excellent work! Thanks for working on this @ShamrockLee . I will give a few days for @zowoq a few more days to respond to this (it seemed they didn't like it initially), and if there will be no reply I'll merge this.
Fix overriding of vendorHash and various attributes via the fixed point attribute support of stdenv.mkDerivation. Pass as derivation attributes goModules, modRoot, vendorHash, deleteVendor, and proxyVendor. Move goModules and vendorHash out of passthru. Co-authored-by: Doron Behar <[email protected]>
1d618a3
to
eed069a
Compare
The package in the overriding example in |
Haven't responded to any of the new changes happened to the PR recently.
rl-2411.section.md: fix typo from #225051
The
The parentheses ought to be curly braces. I've opened PR #336061 to fix it. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/overrideattrs-and-go-query/50919/2 |
One of my overlays broke because of a mistake I did but I think we can avoid that. Fix in #339042 |
@doronbehar I proposed |
Description of changes
The Go package builder
buildGoModule
is refactored to adopt the overlay-stylestdenv.mkDerivation
(#119942) and to fix overriding. One can now overridevendorHash
usingoverrideAttrs
. This addresses #86349 (comment)The
goModules
andvendorHash
attributes are moved out ofpassthru
as they are already exposed asstdenv.mkDerivation
attributes. They can still be accessed aspet.vendorHash
, but no longerpet.passthru.vendorHash
. The builder now only addsgo
topassthru
.To address the issue of
vendorHash = null
throughoverrideAttrs
may break the overriding ofgoModules
, this PR also provides an overridablepassthru.overrideModAttrs
that will be applied togoModules
whenvendorHash
is notnull
.Closes #86349
Comparison to similar PRs:
In this PR, the diff of
pkgs/build-support/go/module.nix
is shorter than #171586.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/
)