diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index 448143f76908..469a8bd67295 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -188,6 +188,12 @@ let ''} '' + '' + # currently pie is only enabled by default in pkgsMusl + # this will respect the `hardening{Disable,Enable}` flags if set + if [[ $NIX_HARDENING_ENABLE =~ "pie" ]]; then + export GOFLAGS="-buildmode=pie $GOFLAGS" + fi + runHook postConfigure ''; diff --git a/pkgs/build-support/go/package.nix b/pkgs/build-support/go/package.nix index ba1ab37a0c0e..9106bf9796eb 100644 --- a/pkgs/build-support/go/package.nix +++ b/pkgs/build-support/go/package.nix @@ -134,6 +134,12 @@ let export GOPATH=$NIX_BUILD_TOP/go:$GOPATH export GOCACHE=$TMPDIR/go-cache + # currently pie is only enabled by default in pkgsMusl + # this will respect the `hardening{Disable,Enable}` flags if set + if [[ $NIX_HARDENING_ENABLE =~ "pie" ]]; then + export GOFLAGS="-buildmode=pie $GOFLAGS" + fi + runHook postConfigure '';