diff options
Diffstat (limited to 'pkgs/development/go-modules/generic/default.nix')
-rw-r--r-- | pkgs/development/go-modules/generic/default.nix | 27 |
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 |