diff --git a/doc/languages-frameworks/go.section.md b/doc/languages-frameworks/go.section.md index b20a8d0c354..8bcbbd323e3 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 968664f81c7..58747d11a59 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 0fb51b68eca..6700dec082b 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