git.iko.soy/typeable/nixpkgs
on master help sign in
buildGo{Package,Module}: set trimpath in GOFLAGS

Also drop removeReferencesTo `-trimpath` removes all file system paths from the compiled executable, this should improve reproducibility.

commit4e9f7bbf8573d07f7b0c87d97c026cd4aad5a758 authorzowoq <59103226+zowoq@users.noreply.github.com> dateThu 29 Oct 2020, 13:27 (6 years ago) parent9f035ff
2 files changed+6−21
pkgs/development/go-modules/generic/default.nix+3−11 pkgs/development/go-packages/generic/default.nix+3−10
pkgs/development/go-modules/generic/default.nix+3−11
@@ -1,4 +1,4 @@
1−{ go, cacert, git, lib, removeReferencesTo, stdenv, vend }:
1+{ go, cacert, git, lib, stdenv, vend }:
22
33{ name ? "${args'.pname}-${args'.version}"
44, src
@@ -43,10 +43,6 @@ with builtins;
4343let
4444 args = removeAttrs args' [ "overrideModAttrs" "vendorSha256" "disabled" ];
4545
46− removeReferences = [ ] ++ lib.optional (!allowGoReference) go;
47−
48− removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
49−
5046 go-modules = if vendorSha256 != null then go.stdenv.mkDerivation (let modArgs = {
5147
5248 name = "${name}-go-modules";
@@ -121,12 +117,12 @@ let
121117 ) // overrideModAttrs modArgs) else "";
122118
123119 package = go.stdenv.mkDerivation (args // {
124− nativeBuildInputs = [ removeReferencesTo go ] ++ nativeBuildInputs;
120+ nativeBuildInputs = [ go ] ++ nativeBuildInputs;
125121
126122 inherit (go) GOOS GOARCH;
127123
128124 GO111MODULE = "on";
129− GOFLAGS = "-mod=vendor";
125+ GOFLAGS = [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
130126
131127 configurePhase = args.configurePhase or ''
132128 runHook preConfigure
@@ -229,10 +225,6 @@ let
229225 runHook postInstall
230226 '';
231227
232− preFixup = (args.preFixup or "") + ''
233− find $out/{bin,libexec,lib} -type f 2>/dev/null | xargs -r ${removeExpr removeReferences} || true
234− '';
235−
236228 strictDeps = true;
237229
238230 disallowedReferences = lib.optional (!allowGoReference) go;
pkgs/development/go-packages/generic/default.nix+3−10
@@ -1,5 +1,5 @@
11{ go, govers, lib, fetchgit, fetchhg, fetchbzr, rsync
2−, removeReferencesTo, fetchFromGitHub, stdenv }:
2+, fetchFromGitHub, stdenv }:
33
44{ buildInputs ? []
55, nativeBuildInputs ? []
@@ -44,10 +44,6 @@
4444with builtins;
4545
4646let
47− removeReferences = [ ] ++ lib.optional (!allowGoReference) go;
48−
49− removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
50−
5147 dep2src = goDep:
5248 {
5349 inherit (goDep) goPackagePath;
@@ -78,7 +74,7 @@ let
7874 package = stdenv.mkDerivation (
7975 (builtins.removeAttrs args [ "goPackageAliases" "disabled" "extraSrcs"]) // {
8076
81− nativeBuildInputs = [ removeReferencesTo go ]
77+ nativeBuildInputs = [ go ]
8278 ++ (lib.optional (!dontRenameImports) govers) ++ nativeBuildInputs;
8379 buildInputs = buildInputs;
8480
@@ -88,6 +84,7 @@ let
8884 GOHOSTOS = go.GOHOSTOS or null;
8985
9086 GO111MODULE = "off";
87+ GOFLAGS = lib.optionals (!allowGoReference) [ "-trimpath" ];
9188
9289 GOARM = toString (stdenv.lib.intersectLists [(stdenv.hostPlatform.parsed.cpu.version or "")] ["5" "6" "7"]);
9390
@@ -225,10 +222,6 @@ let
225222 runHook postInstall
226223 '';
227224
228− preFixup = preFixup + ''
229− find $out/{bin,libexec,lib} -type f 2>/dev/null | xargs -r ${removeExpr removeReferences} || true
230− '';
231−
232225 strictDeps = true;
233226
234227 shellHook = ''