summary refs log tree commit diff
path: root/pkgs/development/go-modules
diff options
context:
space:
mode:
authorzowoq <59103226+zowoq@users.noreply.github.com>2021-07-25 19:33:20 +1000
committerzowoq <59103226+zowoq@users.noreply.github.com>2021-08-06 09:10:09 +1000
commita4461b97c6b3b4b7241dd0e3f44263afd350be76 (patch)
tree93ab1258af858d6882bb339d3d5d743211cda251 /pkgs/development/go-modules
parentb60dde0c1eadd1e62a5e26adb4c4b6c4e03050d2 (diff)
downloadnixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.tar
nixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.tar.gz
nixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.tar.bz2
nixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.tar.lz
nixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.tar.xz
nixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.tar.zst
nixpkgs-a4461b97c6b3b4b7241dd0e3f44263afd350be76.zip
buildGoModule: add proxyVendor
Diffstat (limited to 'pkgs/development/go-modules')
-rw-r--r--pkgs/development/go-modules/generic/default.nix27
1 files changed, 22 insertions, 5 deletions
diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix
index 58747d11a59..5ab5818a6c1 100644
--- a/pkgs/development/go-modules/generic/default.nix
+++ b/pkgs/development/go-modules/generic/default.nix
@@ -29,6 +29,10 @@
 # Whether to run the vend tool to regenerate the vendor directory.
 # This is useful if any dependency contain C files.
 , runVend ? false
+# Whether to fetch (go mod download) and proxy the vendor directory.
+# This is useful if any dependency has case-insensitive conflicts
+# which will produce platform dependant `vendorSha256` checksums.
+, proxyVendor ? false
 
 # We want parallel builds by default
 , enableParallelBuilding ? true
@@ -46,6 +50,8 @@
 
 with builtins;
 
+assert (runVend == true && proxyVendor == true) -> throw "can't use `runVend` and `proxyVendor` together";
+
 assert goPackagePath != "" -> throw "`goPackagePath` is not needed with `buildGoModule`";
 
 let
@@ -97,6 +103,9 @@ let
     ${if runVend then ''
       echo "running 'vend' to rewrite vendor folder"
       ${vend}/bin/vend
+    '' else if proxyVendor then ''
+      mkdir -p "''${GOPATH}/pkg/mod/cache/download"
+      go mod download
     '' else ''
       go mod vendor
     ''}
@@ -109,8 +118,12 @@ let
     installPhase = args.modInstallPhase or ''
       runHook preInstall
 
-      # remove cached lookup results and tiles
+    ${if proxyVendor then ''
+      rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb"
+      cp -r --reflink=auto "''${GOPATH}/pkg/mod/cache/download" $out
+    '' else ''
       cp -r --reflink=auto vendor $out
+    ''}
 
       runHook postInstall
     '';
@@ -130,7 +143,7 @@ let
     inherit (go) GOOS GOARCH;
 
     GO111MODULE = "on";
-    GOFLAGS = [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
+    GOFLAGS = lib.optionals (!proxyVendor) [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
 
     configurePhase = args.configurePhase or ''
       runHook preConfigure
@@ -138,11 +151,15 @@ let
       export GOCACHE=$TMPDIR/go-cache
       export GOPATH="$TMPDIR/go"
       export GOSUMDB=off
-      export GOPROXY=off
       cd "$modRoot"
     '' + lib.optionalString (go-modules != "") ''
-      rm -rf vendor
-      cp -r --reflink=auto ${go-modules} vendor
+      ${if proxyVendor then ''
+        export GOPROXY=file://${go-modules}
+      '' else ''
+        export GOPROXY=off
+        rm -rf vendor
+        cp -r --reflink=auto ${go-modules} vendor
+      ''}
     '' + ''
 
       runHook postConfigure