Skip to content

Commit

Permalink
Merge pull request #276685 from katexochen/buildGoModule/buildid
Browse files Browse the repository at this point in the history
buildGoModule: always set `-buildid=` as ldflag
  • Loading branch information
Mic92 authored Jan 14, 2024
2 parents d841ab8 + 77d6ba8 commit a292058
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkgs/applications/networking/go-graft/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildGoModule rec {

CGO_ENABLED = 0;

ldflags = [ "-X github.com/mzz2017/gg/cmd.Version=${version}" "-s" "-w" "-buildid=" ];
ldflags = [ "-X github.com/mzz2017/gg/cmd.Version=${version}" "-s" "-w" ];
vendorHash = "sha256-fnM4ycqDyruCdCA1Cr4Ki48xeQiTG4l5dLVuAafEm14=";
subPackages = [ "." ];

Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/version-management/gitsign/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ buildGoModule rec {

nativeBuildInputs = [ makeWrapper ];

ldflags = [ "-s" "-w" "-buildid=" "-X github.com/sigstore/gitsign/pkg/version.gitVersion=${version}" ];
ldflags = [ "-s" "-w" "-X github.com/sigstore/gitsign/pkg/version.gitVersion=${version}" ];

preCheck = ''
# test all paths
Expand Down
6 changes: 6 additions & 0 deletions pkgs/build-support/go/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
# Not needed with buildGoModule
, goPackagePath ? ""

, ldflags ? [ ]

# needed for buildFlags{,Array} warning
, buildFlags ? ""
, buildFlagsArray ? ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -301,4 +306,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
6 changes: 6 additions & 0 deletions pkgs/build-support/go/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

, CGO_ENABLED ? go.CGO_ENABLED

, ldflags ? [ ]

# needed for buildFlags{,Array} warning
, buildFlags ? ""
, buildFlagsArray ? ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pkgs/by-name/at/athens/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildGoModule rec {
vendorHash = "sha256-8+PdkanodNZW/xeFf+tDm3Ej7DRSpBBtiT/CqjnWthw=";

CGO_ENABLED = "0";
ldflags = [ "-s" "-w" "-buildid=" "-X github.com/gomods/athens/pkg/build.version=${version}" ];
ldflags = [ "-s" "-w" "-X github.com/gomods/athens/pkg/build.version=${version}" ];

subPackages = [ "cmd/proxy" ];

Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/up/uplosi/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildGo121Module rec {
vendorHash = "sha256-RsjUPLe8omoN+XGyNhHDxzNfZR7VVTkh/f/On1oCRqM=";

CGO_ENABLED = "0";
ldflags = [ "-s" "-w" "-buildid=" "-X main.version=${version}" ];
ldflags = [ "-s" "-w" "-X main.version=${version}" ];
flags = [ "-trimpath" ];

meta = with lib; {
Expand Down
6 changes: 5 additions & 1 deletion pkgs/development/tools/gofumpt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ buildGoModule rec {

CGO_ENABLED = "0";

ldflags = "-s -w -X main.version=v${version}";
ldflags = [
"-s"
"-w"
"-X main.version=v${version}"
];

checkFlags = [
# Requires network access (Error: module lookup disabled by GOPROXY=off).
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/tools/kind/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildGoModule rec {

CGO_ENABLED = 0;
GOFLAGS = [ "-trimpath" ];
ldflags = [ "-buildid=" "-w" ];
ldflags = [ "-w" ];

doCheck = false;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/networking/tun2socks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildGoModule rec {
vendorHash = "sha256-zeiOcn33PnyoseYb0wynkn7MfGp3rHEYBStY98C6aR8=";

ldflags = [
"-w" "-s" "-buildid="
"-w" "-s"
"-X github.com/xjasonlyu/tun2socks/v2/internal/version.Version=v${version}"
"-X github.com/xjasonlyu/tun2socks/v2/internal/version.GitCommit=v${version}"
];
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/networking/v2ray/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ buildGoModule rec {
# https://github.com/Mic92/nix-update/pull/95
vendorHash = "sha256-ZBvHu4BEmQi6PQwRHuVwx/6X4gBqlRR44OktKRBGcs4=";

ldflags = [ "-s" "-w" "-buildid=" ];
ldflags = [ "-s" "-w" ];

subPackages = [ "main" ];

Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/networking/xray/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ buildGoModule rec {

doCheck = false;

ldflags = [ "-s" "-w" "-buildid=" ];
ldflags = [ "-s" "-w" ];
subPackages = [ "main" ];

installPhase = ''
Expand Down
1 change: 0 additions & 1 deletion pkgs/tools/security/slsa-verifier/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ buildGoModule rec {
ldflags = [
"-s"
"-w"
"-buildid="
"-X sigs.k8s.io/release-utils/version.gitVersion=${version}"
];

Expand Down
4 changes: 0 additions & 4 deletions pkgs/tools/security/step-ca/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ buildGoModule rec {

vendorHash = "sha256-AXMMpzXEhdKSGeVg/KK2NEgalxIXP6DUTcoxOQVqow4=";

ldflags = [
"-buildid="
];

nativeBuildInputs = lib.optionals hsmSupport [
pkg-config
];
Expand Down

0 comments on commit a292058

Please sign in to comment.