Skip to content

buildGoModule: alias vendorSha256 to vendorHash#225371

Merged
zowoq merged 1 commit intoNixOS:masterfrom
qowoz:go-hash-cleanup
May 26, 2023
Merged

buildGoModule: alias vendorSha256 to vendorHash#225371
zowoq merged 1 commit intoNixOS:masterfrom
qowoz:go-hash-cleanup

Conversation

@zowoq
Copy link
Contributor

@zowoq zowoq commented Apr 9, 2023

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. label Apr 9, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Apr 9, 2023
@zowoq
Copy link
Contributor Author

zowoq commented Apr 9, 2023

cc @NixOS/golang @ajs124

Comment on lines 147 to 148
Copy link
Contributor

@ShamrockLee ShamrockLee Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} // lib.optionalAttrs (args' ? vendorSha256 || vendorHash == "") {
outputHashAlgo = "sha256";
outputHashAlgo = if args' ? vendorSha256 || vendorHash == "" then "sha256" else null;

Passing null would make the structure simpler than using lib.optionalAttrs.

@qbit
Copy link
Contributor

qbit commented Apr 26, 2023

Maybe a dumb question, but what's the advantage of doing this over a blanket change to vendorHash? Is it to avoid issues with stuff in the wild?

@zowoq
Copy link
Contributor Author

zowoq commented Apr 27, 2023

Yeah, to outright remove it is kind of a hassle and really needs to be done with a deprecation over a release cycle.

@zowoq zowoq marked this pull request as ready for review May 25, 2023 21:58
@zowoq zowoq requested review from Mic92 and kalbasit as code owners May 25, 2023 21:58
@zowoq
Copy link
Contributor Author

zowoq commented May 25, 2023

@ShamrockLee I'd like to merge this first as it'll make the subsequent PRs simpler if we don't need to handle _unset and only need vendorSha256 in a couple of places.

Copy link
Contributor

@ShamrockLee ShamrockLee May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, vendorHash ? args'.vendorSha256
, vendorHash ? args'.vendorSha256 or throw "buildGoModule: vendorHash is missing"

The default error message would be "vendorSha256 is missing" without the or throw

nix-repl> pkgs.buildGoModule { src = pkgs.emptyDirectory; name = "empty"; }
error: attribute 'vendorSha256' missing

       at /data/data/com.termux.nix/files/home/Projects/NixOS/nixpkgs/pkgs/build-support/go/module.nix:22:16:

           21| # rely on the vendor folder within the source.
           22| , vendorHash ? args'.vendorSha256
             |                ^
           23| # Whether to delete the vendor folder supplied with the source.
«derivation

Other than that, LGTM!

Copy link
Contributor

@ShamrockLee ShamrockLee May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for yet another question.

How would vendorHash == "" (meaning go-modules.outputHash == "") be legal for a fixed-output derivation? Is that condition obsolete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't allowed in derivations, it's a convenience for generating the go-modules hash otherwise it errors with an empty hash:

error: empty hash requires explicit hash type

Currently:

warning: found empty hash, assuming 'sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
these 2 derivations will be built:
  /nix/store/f9lqyz4nlzg4smd3qz45dg1vkxk8qzi0-fzf-0.40.0-go-modules.drv
  /nix/store/3lpry8y4535gdhbvf6y78na1qphf5857-fzf-0.40.0.drv
building '/nix/store/f9lqyz4nlzg4smd3qz45dg1vkxk8qzi0-fzf-0.40.0-go-modules.drv'...
unpacking sources
unpacking source archive /nix/store/ph5jpqrhd05y17b94ig0pq3574f7c9ay-source
source root is source
patching sources
configuring
building
go: downloading golang.org/x/sys v0.7.0
go: downloading github.com/mattn/go-isatty v0.0.17
go: downloading github.com/mattn/go-runewidth v0.0.14
go: downloading github.com/rivo/uniseg v0.4.4
go: downloading github.com/gdamore/tcell/v2 v2.5.4
go: downloading github.com/mattn/go-shellwords v1.0.12
go: downloading github.com/saracen/walker v0.1.3
go: downloading golang.org/x/term v0.7.0
go: downloading golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
go: downloading golang.org/x/text v0.5.0
go: downloading github.com/gdamore/encoding v1.0.0
go: downloading github.com/lucasb-eyer/go-colorful v1.2.0
installing
error: hash mismatch in fixed-output derivation '/nix/store/f9lqyz4nlzg4smd3qz45dg1vkxk8qzi0-fzf-0.40.0-go-modules.drv':
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-SSz4oHUgfMRbvpdIl1xepfckef1HDA1y646FWnyBp6o=
error: 1 dependencies of derivation '/nix/store/3lpry8y4535gdhbvf6y78na1qphf5857-fzf-0.40.0.drv' failed to build

Does that answer your question or have I misunderstood what you were asking?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That makes sense.

@zowoq zowoq merged commit 0ba51a5 into NixOS:master May 26, 2023
@zowoq zowoq deleted the go-hash-cleanup branch May 26, 2023 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: golang Go is a high-level general purpose programming language that is statically typed and compiled. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants