From 6c007869b65210c9540f108203f79e7f62502bb6 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <hg@lukegb.com>
Date: Sun, 18 Oct 2020 14:23:22 +0000
Subject: [PATCH] buildGo: remove some additional references to srcs

---
 third_party/tvl/nix/buildGo/default.nix | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/third_party/tvl/nix/buildGo/default.nix b/third_party/tvl/nix/buildGo/default.nix
index a2396dc3f7..18b69dcd8a 100644
--- a/third_party/tvl/nix/buildGo/default.nix
+++ b/third_party/tvl/nix/buildGo/default.nix
@@ -21,7 +21,7 @@ let
     replaceStrings
     toString;
 
-  inherit (pkgs) lib go runCommand fetchFromGitHub protobuf symlinkJoin;
+  inherit (pkgs) lib go runCommand fetchFromGitHub protobuf symlinkJoin removeReferencesTo;
 
   # Helpers for low-level Go compiler invocations
   spaceOut = lib.concatStringsSep " ";
@@ -42,6 +42,8 @@ let
 
   pathToName = p: replaceStrings ["/"] ["_"] (toString p);
 
+  removeRefs = refs: "${removeReferencesTo}/bin/remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") ([ go ] ++ refs)}";
+
   # Add an `overrideGo` attribute to a function result that works
   # similar to `overrideAttrs`, but is used specifically for the
   # arguments passed to Go builders.
@@ -55,10 +57,11 @@ let
   program = { name, srcs, deps ? [], x_defs ? {} }:
   let uniqueDeps = allDeps (map (d: d.gopkg) deps);
   in runCommand name {} ''
-    ${go}/bin/go tool compile -o ${name}.a -trimpath=$PWD -trimpath=${go} ${includeSources uniqueDeps} ${spaceOut srcs}
+    ${go}/bin/go tool compile -o ${name}.a -trimpath="$PWD;${go}" ${includeSources uniqueDeps} ${spaceOut srcs}
     mkdir -p $out/bin
     export GOROOT_FINAL=go
     ${go}/bin/go tool link -o $out/bin/${name} -buildid nix ${xFlags x_defs} ${includeLibs uniqueDeps} ${name}.a
+    ${removeRefs srcs} $out/bin/${name}
   '';
 
   # Build a Go library assembled out of the specified files.
@@ -87,8 +90,9 @@ let
       mkdir -p $out/${path}
       ${srcList path (map (s: "${s}") srcs)}
       ${asmBuild}
-      ${go}/bin/go tool compile -pack ${asmLink} -o $out/${path}.a -trimpath=$PWD -trimpath=${go} -p ${path} ${includeSources uniqueDeps} ${spaceOut srcs}
+      ${go}/bin/go tool compile -pack ${asmLink} -o $out/${path}.a -trimpath="$PWD;${go}" -p ${path} ${includeSources uniqueDeps} ${spaceOut srcs}
       ${asmPack}
+      ${removeRefs srcs} $out/${path}.a
     '') // {
       inherit gopkg;
       goDeps = uniqueDeps;