From 24c5e41124c79aeb2a56b3d386c00ed16230a329 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Tue, 14 Jun 2022 18:54:18 +0800 Subject: [PATCH] buildGoApplication: 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. This is a port of https://github.com/NixOS/nixpkgs/commit/155ae682a5122960aed61724b4ed8c9711b53e99 --- builder/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/default.nix b/builder/default.nix index 170d32b..2310fa5 100644 --- a/builder/default.nix +++ b/builder/default.nix @@ -260,7 +260,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 'imports .*?: no Go files in'; then echo "$OUT" >&2 return 1