diff options
author | Paul Meyer <49727155+katexochen@users.noreply.github.com> | 2023-12-30 20:25:39 +0100 |
---|---|---|
committer | Paul Meyer <49727155+katexochen@users.noreply.github.com> | 2024-03-28 07:57:19 +0100 |
commit | 63a052eb57590c79a94372af7bc329e698dec5ba (patch) | |
tree | 9ee0222abbc5502cb5744a0a1671cce9dfa9bd2e /pkgs/build-support/go | |
parent | 8f72bd17eae0d1a7fcb63e3f1a3baa7dadebef68 (diff) |
buildGoModule: warn if `-trimpath` or `-mod=` is used
in GOFLAGS
Diffstat (limited to 'pkgs/build-support/go')
-rw-r--r-- | pkgs/build-support/go/module.nix | 10 | ||||
-rw-r--r-- | pkgs/build-support/go/package.nix | 7 |
2 files changed, 13 insertions, 4 deletions
diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index 153b675d48aef..7d2960f699dc7 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -41,6 +41,8 @@ , ldflags ? [ ] +, GOFLAGS ? [ ] + # needed for buildFlags{,Array} warning , buildFlags ? "" , buildFlagsArray ? "" @@ -153,11 +155,13 @@ let inherit (go) GOOS GOARCH; - GOFLAGS = lib.optionals (!proxyVendor) [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ]; + GOFLAGS = GOFLAGS + ++ lib.optional (!proxyVendor) "-mod=vendor" + ++ lib.optional (!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=" ]; + ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid="; configurePhase = args.configurePhase or ('' runHook preConfigure @@ -307,4 +311,6 @@ lib.warnIf (args' ? vendorSha256) "`vendorSha256` is deprecated. Use `vendorHash 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" +lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" +lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" package diff --git a/pkgs/build-support/go/package.nix b/pkgs/build-support/go/package.nix index 8ca5ca0dca011..94a459c267f36 100644 --- a/pkgs/build-support/go/package.nix +++ b/pkgs/build-support/go/package.nix @@ -39,6 +39,8 @@ , ldflags ? [ ] +, GOFLAGS ? [ ] + # needed for buildFlags{,Array} warning , buildFlags ? "" , buildFlagsArray ? "" @@ -89,12 +91,12 @@ let GO111MODULE = "off"; GOTOOLCHAIN = "local"; - GOFLAGS = lib.optionals (!allowGoReference) [ "-trimpath" ]; + GOFLAGS = GOFLAGS ++ lib.optional (!allowGoReference) "-trimpath" ; 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=" ]; + ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid="; configurePhase = args.configurePhase or ('' runHook preConfigure @@ -286,4 +288,5 @@ 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" +lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" package |