go: set buildmode=exe when CGO_ENABLED=0

To avoid breaking previous documented[^1] behavior of CGO_ENABLED=0
producing fully static binaries we set buildmode=exe. Sadly go
does not support static-pie binaries so this means these packages
lose ASLR.

This is likely to be revisited after branch-off, as
go packages in the main package set with CGO_ENABLED=0 not having
ASLR is not good security posture in the long term and makes
go packages inconsistent with other languages.

[1]: See #var-go-CGO_ENABLED

Fixes: #456953
Fixes: 08aadbf8d4
This commit is contained in:
Luna Nova
2025-11-06 08:00:41 -08:00
parent 7e415ae008
commit 4d1d61c75c
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -253,6 +253,9 @@ lib.extendMkDerivation {
if [ -f "$NIX_CC_FOR_TARGET/nix-support/dynamic-linker" ]; then
export GO_LDSO=$(cat $NIX_CC_FOR_TARGET/nix-support/dynamic-linker)
fi
if [ "$CGO_ENABLED" = "0" ]; then
export GOFLAGS="-buildmode=exe $GOFLAGS"
fi
cd "$modRoot"
''
+ lib.optionalString (finalAttrs.vendorHash != null) ''
+1 -1
View File
@@ -15,7 +15,7 @@ let
skopeo' = skopeo.override { buildGoModule = buildGoModule; };
athens' = athens.override { buildGoModule = buildGoModule; };
expectedCgoEnabledType = "DYN";
expectedCgoDisabledType = "DYN";
expectedCgoDisabledType = "EXE";
in
{
skopeo = testers.testVersion { package = skopeo'; };