diff options
author | Doron Behar <doron.behar@gmail.com> | 2023-04-21 18:08:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-22 11:08:54 +1000 |
commit | a82c8611ce47491bd3f80e2219bfaab06d47ec2f (patch) | |
tree | 67d989bf32650253db340e1be849a71153fe18b5 /doc/languages-frameworks/go.section.md | |
parent | e025c6f560d19c5c72bfcc770bb5e9d18295d0d4 (diff) | |
download | nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.tar nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.tar.gz nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.tar.bz2 nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.tar.lz nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.tar.xz nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.tar.zst nixlib-a82c8611ce47491bd3f80e2219bfaab06d47ec2f.zip |
buildGoModule: don't inherit build hooks when building go-modules (#225349)
* buildGoModule: don't inherit postBuild hook when building go-modules This is a slight revert of 5ce647b8bf7aee0d3862006d94df7878c7fc03a6 (#212800). Inheriting these hooks in the `.go-modules` derivation can be confusing: One doesn't expect them to run when generating the fixed output modules derivation, but only on the main derivation. A `postBuild` hook that adds some files to $out will cause a very hard to debug issue[1]. This commit adds support for a dedicated `modPostBuild` hook that will be used only by the derivation building `.go-modules`. Additionally, `go.section.md` now explains these attributes behavior better. [1]: https://discourse.nixos.org/t/cant-update-a-go-package-getting-go-inconsistent-vendoring/27063/6 Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Diffstat (limited to 'doc/languages-frameworks/go.section.md')
-rw-r--r-- | doc/languages-frameworks/go.section.md | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/doc/languages-frameworks/go.section.md b/doc/languages-frameworks/go.section.md index cefdd68c3520..c697a6908751 100644 --- a/doc/languages-frameworks/go.section.md +++ b/doc/languages-frameworks/go.section.md @@ -20,6 +20,7 @@ In the following is an example expression using `buildGoModule`, the following a To obtain the actual hash, set `vendorHash = lib.fakeSha256;` and run the build ([more details here](#sec-source-hashes)). - `proxyVendor`: Fetches (go mod download) and proxies the vendor directory. This is useful if your code depends on c code and go mod tidy does not include the needed sources to build or if any dependency has case-insensitive conflicts which will produce platform dependant `vendorHash` checksums. +- `modPostBuild`: Shell commands to run after the build of the go-modules executes `go mod vendor`, and before calculating fixed output derivation's `vendorHash` (or `vendorSha256`). Note that if you change this attribute, you need to update `vendorHash` (or `vendorSha256`) attribute. ```nix pet = buildGoModule rec { @@ -114,7 +115,16 @@ done ## Attributes used by the builders {#ssec-go-common-attributes} -Both `buildGoModule` and `buildGoPackage` can be tweaked to behave slightly differently, if the following attributes are used: +Many attributes [controlling the build phase](#variables-controlling-the-build-phase) are respected by both `buildGoModule` and `buildGoPackage`. Note that `buildGoModule` reads the following attributes also when building the `vendor/` go-modules fixed output derivation as well: + +- [`sourceRoot`](#var-stdenv-sourceRoot) +- [`prePatch`](#var-stdenv-prePatch) +- [`patches`](#var-stdenv-patches) +- [`patchFlags`](#var-stdenv-patchFlags) +- [`postPatch`](#var-stdenv-postPatch) +- [`preBuild`](#var-stdenv-preBuild) + +In addition to the above attributes, and the many more variables respected also by `stdenv.mkDerivation`, both `buildGoModule` and `buildGoPackage` respect Go-specific attributes that tweak them to behave slightly differently: ### `ldflags` {#var-go-ldflags} |