From 155ae682a5122960aed61724b4ed8c9711b53e99 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 3 Jun 2021 17:45:04 +0200 Subject: 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. --- pkgs/development/go-modules/generic/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pkgs/development/go-modules') diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 8246eaefed4..10beb80f2e6 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -7,6 +7,9 @@ , passthru ? {} , patches ? [] +# Go linker flags, passed to go via -ldflags +, ldflags ? [] + # A function to override the go-modules derivation , overrideModAttrs ? (_oldAttrs : {}) @@ -153,7 +156,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[@]}" -v -p $NIX_BUILD_CORES $d 2>&1)"; then + if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${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 -- cgit 1.4.1