buildGoModule: add proxyVendor

zowoq a4461b97 b60dde0c

Changed files
+23 -5
doc
languages-frameworks
pkgs
development
go-modules
generic
+1
doc/languages-frameworks/go.section.md
···
- `vendorSha256`: is the hash of the output of the intermediate fetcher derivation. `vendorSha256` can also take `null` as an input. When `null` is used as a value, rather than fetching the dependencies and vendoring them, we use the vendoring included within the source repo. If you'd like to not have to update this field on dependency changes, run `go mod vendor` in your source repo and set `vendorSha256 = null;`
- `runVend`: runs the vend command to generate the vendor directory. This is useful if your code depends on c code and go mod tidy does not include the needed sources to build.
```nix
pet = buildGoModule rec {
···
- `vendorSha256`: is the hash of the output of the intermediate fetcher derivation. `vendorSha256` can also take `null` as an input. When `null` is used as a value, rather than fetching the dependencies and vendoring them, we use the vendoring included within the source repo. If you'd like to not have to update this field on dependency changes, run `go mod vendor` in your source repo and set `vendorSha256 = null;`
- `runVend`: runs the vend command to generate the vendor directory. This is useful if your code depends on c code and go mod tidy does not include the needed sources to build.
+
- `proxyVendor`: Fetches (go mod download) and proxies the vendor directory. This is useful if any dependency has case-insensitive conflicts which will produce platform dependant `vendorSha256` checksums.
```nix
pet = buildGoModule rec {
+22 -5
pkgs/development/go-modules/generic/default.nix
···
# Whether to run the vend tool to regenerate the vendor directory.
# This is useful if any dependency contain C files.
, runVend ? false
# We want parallel builds by default
, enableParallelBuilding ? true
···
, ... }@args':
with builtins;
assert goPackagePath != "" -> throw "`goPackagePath` is not needed with `buildGoModule`";
···
${if runVend then ''
echo "running 'vend' to rewrite vendor folder"
${vend}/bin/vend
'' else ''
go mod vendor
''}
···
installPhase = args.modInstallPhase or ''
runHook preInstall
-
# remove cached lookup results and tiles
cp -r --reflink=auto vendor $out
runHook postInstall
'';
···
inherit (go) GOOS GOARCH;
GO111MODULE = "on";
-
GOFLAGS = [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
configurePhase = args.configurePhase or ''
runHook preConfigure
···
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
'' + ''
runHook postConfigure
···
# 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
···
, ... }@args':
with builtins;
+
+
assert (runVend == true && proxyVendor == true) -> throw "can't use `runVend` and `proxyVendor` together";
assert goPackagePath != "" -> throw "`goPackagePath` is not needed with `buildGoModule`";
···
${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
''}
···
installPhase = args.modInstallPhase or ''
runHook preInstall
+
${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
'';
···
inherit (go) GOOS GOARCH;
GO111MODULE = "on";
+
GOFLAGS = lib.optionals (!proxyVendor) [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
configurePhase = args.configurePhase or ''
runHook preConfigure
···
export GOCACHE=$TMPDIR/go-cache
export GOPATH="$TMPDIR/go"
export GOSUMDB=off
cd "$modRoot"
'' + lib.optionalString (go-modules != "") ''
+
${if proxyVendor then ''
+
export GOPROXY=file://${go-modules}
+
'' else ''
+
export GOPROXY=off
+
rm -rf vendor
+
cp -r --reflink=auto ${go-modules} vendor
+
''}
'' + ''
runHook postConfigure