buildGoModule: always set -buildid= as ldflag

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2023-12-24 21:05:13 +01:00
parent 1528aeb0b6
commit 891a634876
2 changed files with 12 additions and 0 deletions

View File

@ -39,6 +39,8 @@
# Not needed with buildGoModule
, goPackagePath ? ""
, ldflags ? [ ]
# needed for buildFlags{,Array} warning
, buildFlags ? ""
, buildFlagsArray ? ""
@ -154,6 +156,9 @@ let
GOFLAGS = lib.optionals (!proxyVendor) [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
inherit CGO_ENABLED enableParallelBuilding GO111MODULE GOTOOLCHAIN;
# If not set to an explicit value, set the buildid empty for reproducibility.
ldflags = ldflags ++ lib.optionals (!lib.any (lib.hasPrefix "-buildid=") ldflags) [ "-buildid=" ];
configurePhase = args.configurePhase or (''
runHook preConfigure
@ -300,4 +305,5 @@ in
lib.warnIf (args' ? vendorSha256) "`vendorSha256` is deprecated. Use `vendorHash` instead"
lib.warnIf (buildFlags != "" || buildFlagsArray != "")
"Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`"
lib.warnIf (builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule"
package

View File

@ -37,6 +37,8 @@
, CGO_ENABLED ? go.CGO_ENABLED
, ldflags ? [ ]
# needed for buildFlags{,Array} warning
, buildFlags ? ""
, buildFlagsArray ? ""
@ -91,6 +93,9 @@ let
GOARM = toString (lib.intersectLists [(stdenv.hostPlatform.parsed.cpu.version or "")] ["5" "6" "7"]);
# If not set to an explicit value, set the buildid empty for reproducibility.
ldflags = ldflags ++ lib.optionals (!lib.any (lib.hasPrefix "-buildid=") ldflags) [ "-buildid=" ];
configurePhase = args.configurePhase or (''
runHook preConfigure
@ -280,4 +285,5 @@ let
in
lib.warnIf (buildFlags != "" || buildFlagsArray != "")
"Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`"
lib.warnIf (builtins.elem "-buildid=" ldflags) "`-buildid=` is set by default as ldflag by buildGoModule"
package