diff options
author | zowoq | 2021-07-31 14:57:54 +1000 |
---|---|---|
committer | zowoq | 2021-08-06 09:09:58 +1000 |
commit | b60dde0c1eadd1e62a5e26adb4c4b6c4e03050d2 (patch) | |
tree | 0d6140382130bc3eddc4bfd3e26e88a7da2427ee | |
parent | ed6852a778fefd20ad667493f8d94b917ca76304 (diff) |
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.
-rw-r--r-- | doc/languages-frameworks/go.section.md | 25 | ||||
-rw-r--r-- | pkgs/development/go-modules/generic/default.nix | 5 | ||||
-rw-r--r-- | pkgs/development/go-packages/generic/default.nix | 5 |
3 files changed, 23 insertions, 12 deletions
diff --git a/doc/languages-frameworks/go.section.md b/doc/languages-frameworks/go.section.md index b20a8d0c3549..8bcbbd323e36 100644 --- a/doc/languages-frameworks/go.section.md +++ b/doc/languages-frameworks/go.section.md @@ -112,16 +112,6 @@ done 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} 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} Removes the pre-existing vendor directory. This should only be used if the dependencies included in the vendor folder are broken or incomplete. diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 968664f81c73..58747d11a599 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -10,6 +10,9 @@ # Go linker flags, passed to go via -ldflags , ldflags ? [] +# Go tags, passed to go via -tag +, tags ? [] + # A function to override the go-modules derivation , overrideModAttrs ? (_oldAttrs : {}) @@ -156,7 +159,7 @@ let echo "$d" | grep -q "\(/_\|examples\|Godeps\|testdata\)" && return 0 [ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0 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 echo "$OUT" >&2 return 1 diff --git a/pkgs/development/go-packages/generic/default.nix b/pkgs/development/go-packages/generic/default.nix index 0fb51b68eca6..6700dec082bc 100644 --- a/pkgs/development/go-packages/generic/default.nix +++ b/pkgs/development/go-packages/generic/default.nix @@ -10,6 +10,9 @@ # Go linker flags, passed to go via -ldflags , ldflags ? [] +# Go tags, passed to go via -tag +, tags ? [] + # We want parallel builds by default , enableParallelBuilding ? true @@ -151,7 +154,7 @@ let echo "$d" | grep -q "\(/_\|examples\|Godeps\)" && return 0 [ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0 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 echo "$OUT" >&2 return 1 |