summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2021-06-03 17:45:04 +0200
committerzowoq <59103226+zowoq@users.noreply.github.com>2021-06-05 09:54:36 +1000
commit155ae682a5122960aed61724b4ed8c9711b53e99 (patch)
tree3d6aa4f5435e75d8444994414f4abdbb64ffb5c6 /doc
parent99697d891de658a5b6ea4bd4ea5ef9acfb62ea13 (diff)
downloadnixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.tar
nixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.tar.gz
nixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.tar.bz2
nixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.tar.lz
nixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.tar.xz
nixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.tar.zst
nixpkgs-155ae682a5122960aed61724b4ed8c9711b53e99.zip
buildGoModule/buildGoPackage: Introduce ldflags argument
Previously it was not possible to define multiple ldflags, since only
the last definition applies, and there's some quoting issues with
`buildFlagsArray`. With the new `ldflags` argument it's possible to do
this, e.g.

    ldflags = drv.ldflags or [] ++ [
      "-X main.Version=1.0"
    ]

can now properly append a flag without clearing all previous ldflags.
Diffstat (limited to 'doc')
-rw-r--r--doc/languages-frameworks/go.section.md19
1 files changed, 11 insertions, 8 deletions
diff --git a/doc/languages-frameworks/go.section.md b/doc/languages-frameworks/go.section.md
index b4228d9d313..f52570ac8cc 100644
--- a/doc/languages-frameworks/go.section.md
+++ b/doc/languages-frameworks/go.section.md
@@ -114,21 +114,24 @@ Both `buildGoModule` and `buildGoPackage` can be tweaked to behave slightly diff
 
 ### `buildFlagsArray` and `buildFlags`: {#ex-goBuildFlags-noarray}
 
-These attributes set build flags supported by `go build`. We recommend using `buildFlagsArray`. The most common use case of these attributes is to make the resulting executable aware of its own version. For example:
+These attributes set build flags supported by `go build`. We recommend using `buildFlagsArray`.
 
 ```nix
   buildFlagsArray = [
-    # Note: single quotes are not needed.
-    "-ldflags=-X main.Version=${version} -X main.Commit=${version}"
+    "-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:
+
 ```nix
-  buildFlagsArray = ''
-    -ldflags=
-    -X main.Version=${version}
-    -X main.Commit=${version}
-  '';
+  ldflags = [
+    "-s" "-w"
+    "-X main.Version=${version}"
+    "-X main.Commit=${version}"
+  ];
 ```
 
 ### `deleteVendor` {#var-go-deleteVendor}