From 23c781a810e6133a3c22eea04dc08d820a912ecc Mon Sep 17 00:00:00 2001
From: zowoq <59103226+zowoq@users.noreply.github.com>
Date: Mon, 31 Aug 2020 15:54:19 +1000
Subject: [PATCH] buildGoPackage: check/delete vendor
---
doc/languages-frameworks/go.xml | 9 ++++++++-
pkgs/development/go-packages/generic/default.nix | 15 +++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/doc/languages-frameworks/go.xml b/doc/languages-frameworks/go.xml
index 26414f23c7d2..7cff7a85c62c 100644
--- a/doc/languages-frameworks/go.xml
+++ b/doc/languages-frameworks/go.xml
@@ -117,7 +117,9 @@ deis = buildGoPackage rec {
goDeps = ./deps.nix;
- buildFlags = [ "--tags" "release" ];
+ deleteVendor = true;
+
+ buildFlags = [ "--tags" "release" ];
}
@@ -144,6 +146,11 @@ deis = buildGoPackage rec {
+
+ deleteVendor removes the pre-existing vendor directory. This should only be used if the dependencies included in the vendor folder are broken or incomplete.
+
+
+
buildFlags is a list of flags passed to the go build command.
diff --git a/pkgs/development/go-packages/generic/default.nix b/pkgs/development/go-packages/generic/default.nix
index de0a35b69343..5c54e04652f7 100644
--- a/pkgs/development/go-packages/generic/default.nix
+++ b/pkgs/development/go-packages/generic/default.nix
@@ -29,6 +29,9 @@
# go2nix dependency file
, goDeps ? null
+# Whether to delete the vendor folder supplied with the source.
+, deleteVendor ? false
+
, dontRenameImports ? false
# Do not enable this without good reason
@@ -96,6 +99,18 @@ let
mkdir -p "go/src/$(dirname "$goPackagePath")"
mv "$sourceRoot" "go/src/$goPackagePath"
+ '' + lib.optionalString (deleteVendor == true) ''
+ if [ ! -d "go/src/$goPackagePath/vendor" ]; then
+ echo "vendor folder does not exist, 'deleteVendor' is not needed"
+ exit 10
+ else
+ rm -rf "go/src/$goPackagePath/vendor"
+ fi
+ '' + lib.optionalString (goDeps != null) ''
+ if [ -d "go/src/$goPackagePath/vendor" ]; then
+ echo "vendor folder exists, 'goDeps' is not needed"
+ exit 10
+ fi
'' + lib.flip lib.concatMapStrings goPath ({ src, goPackagePath }: ''
mkdir goPath
(cd goPath; unpackFile "${src}")