forked from mirrors/nixpkgs
buildGo{Module,Package}: add tags
argument
Simpler method of setting tags rather than using some combination of buildFlags, buildFlagsArray, preBuild, etc Using `lib.concatStringsSep ","` as space separated tags are deprecated in go.
This commit is contained in:
parent
ed6852a778
commit
b60dde0c1e
|
@ -112,16 +112,6 @@ done
|
||||||
|
|
||||||
Both `buildGoModule` and `buildGoPackage` can be tweaked to behave slightly differently, if the following attributes are used:
|
Both `buildGoModule` and `buildGoPackage` can be tweaked to behave slightly differently, if the following attributes are used:
|
||||||
|
|
||||||
### `buildFlagsArray` and `buildFlags`: {#ex-goBuildFlags-noarray}
|
|
||||||
|
|
||||||
These attributes set build flags supported by `go build`. We recommend using `buildFlagsArray`.
|
|
||||||
|
|
||||||
```nix
|
|
||||||
buildFlagsArray = [
|
|
||||||
"-tags=release"
|
|
||||||
];
|
|
||||||
```
|
|
||||||
|
|
||||||
### `ldflags` {#var-go-ldflags}
|
### `ldflags` {#var-go-ldflags}
|
||||||
|
|
||||||
Arguments to pass to the Go linker tool via the `-ldflags` argument of `go build`. The most common use case for this argument is to make the resulting executable aware of its own version. For example:
|
Arguments to pass to the Go linker tool via the `-ldflags` argument of `go build`. The most common use case for this argument is to make the resulting executable aware of its own version. For example:
|
||||||
|
@ -134,6 +124,21 @@ Arguments to pass to the Go linker tool via the `-ldflags` argument of `go build
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `tags` {#var-go-tags}
|
||||||
|
|
||||||
|
Arguments to pass to the Go via the `-tags` argument of `go build`. For example:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
tags = [
|
||||||
|
"production"
|
||||||
|
"sqlite"
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
```nix
|
||||||
|
tags = [ "production" ] ++ lib.optionals withSqlite [ "sqlite" ];
|
||||||
|
```
|
||||||
|
|
||||||
### `deleteVendor` {#var-go-deleteVendor}
|
### `deleteVendor` {#var-go-deleteVendor}
|
||||||
|
|
||||||
Removes the pre-existing vendor directory. This should only be used if the dependencies included in the vendor folder are broken or incomplete.
|
Removes the pre-existing vendor directory. This should only be used if the dependencies included in the vendor folder are broken or incomplete.
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
# Go linker flags, passed to go via -ldflags
|
# Go linker flags, passed to go via -ldflags
|
||||||
, ldflags ? []
|
, ldflags ? []
|
||||||
|
|
||||||
|
# Go tags, passed to go via -tag
|
||||||
|
, tags ? []
|
||||||
|
|
||||||
# A function to override the go-modules derivation
|
# A function to override the go-modules derivation
|
||||||
, overrideModAttrs ? (_oldAttrs : {})
|
, overrideModAttrs ? (_oldAttrs : {})
|
||||||
|
|
||||||
|
@ -156,7 +159,7 @@ let
|
||||||
echo "$d" | grep -q "\(/_\|examples\|Godeps\|testdata\)" && return 0
|
echo "$d" | grep -q "\(/_\|examples\|Godeps\|testdata\)" && return 0
|
||||||
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0
|
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0
|
||||||
local OUT
|
local OUT
|
||||||
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
|
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
|
||||||
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
|
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
|
||||||
echo "$OUT" >&2
|
echo "$OUT" >&2
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
# Go linker flags, passed to go via -ldflags
|
# Go linker flags, passed to go via -ldflags
|
||||||
, ldflags ? []
|
, ldflags ? []
|
||||||
|
|
||||||
|
# Go tags, passed to go via -tag
|
||||||
|
, tags ? []
|
||||||
|
|
||||||
# We want parallel builds by default
|
# We want parallel builds by default
|
||||||
, enableParallelBuilding ? true
|
, enableParallelBuilding ? true
|
||||||
|
|
||||||
|
@ -151,7 +154,7 @@ let
|
||||||
echo "$d" | grep -q "\(/_\|examples\|Godeps\)" && return 0
|
echo "$d" | grep -q "\(/_\|examples\|Godeps\)" && return 0
|
||||||
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0
|
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0
|
||||||
local OUT
|
local OUT
|
||||||
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
|
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
|
||||||
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
|
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
|
||||||
echo "$OUT" >&2
|
echo "$OUT" >&2
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in a new issue