buildGoPackage: check/delete vendor

This commit is contained in:
zowoq 2020-08-31 15:54:19 +10:00
parent 945fdbe1b9
commit 23c781a810
2 changed files with 23 additions and 1 deletions

View File

@ -117,7 +117,9 @@ deis = buildGoPackage rec {
goDeps = ./deps.nix; <co xml:id='ex-buildGoPackage-3' /> goDeps = ./deps.nix; <co xml:id='ex-buildGoPackage-3' />
buildFlags = [ "--tags" "release" ]; <co xml:id='ex-buildGoPackage-4' /> deleteVendor = true; <co xml:id='ex-buildGoPackage-4' />
buildFlags = [ "--tags" "release" ]; <co xml:id='ex-buildGoPackage-5' />
} }
</programlisting> </programlisting>
</example> </example>
@ -144,6 +146,11 @@ deis = buildGoPackage rec {
</para> </para>
</callout> </callout>
<callout arearefs='ex-buildGoPackage-4'> <callout arearefs='ex-buildGoPackage-4'>
<para>
<varname>deleteVendor</varname> removes the pre-existing vendor directory. This should only be used if the dependencies included in the vendor folder are broken or incomplete.
</para>
</callout>
<callout arearefs='ex-buildGoPackage-5'>
<para> <para>
<varname>buildFlags</varname> is a list of flags passed to the go build command. <varname>buildFlags</varname> is a list of flags passed to the go build command.
</para> </para>

View File

@ -29,6 +29,9 @@
# go2nix dependency file # go2nix dependency file
, goDeps ? null , goDeps ? null
# Whether to delete the vendor folder supplied with the source.
, deleteVendor ? false
, dontRenameImports ? false , dontRenameImports ? false
# Do not enable this without good reason # Do not enable this without good reason
@ -96,6 +99,18 @@ let
mkdir -p "go/src/$(dirname "$goPackagePath")" mkdir -p "go/src/$(dirname "$goPackagePath")"
mv "$sourceRoot" "go/src/$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 }: '' '' + lib.flip lib.concatMapStrings goPath ({ src, goPackagePath }: ''
mkdir goPath mkdir goPath
(cd goPath; unpackFile "${src}") (cd goPath; unpackFile "${src}")