diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 6a8b07b633ef..7e1ce67539b4 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -99,8 +99,12 @@ rec { mkDerivationFromStdenv = withOldMkDerivation old (stdenv: mkDerivationSuper: args: if stdenv.hostPlatform.isDarwin then throw "Cannot build fully static binaries on Darwin/macOS" - else (mkDerivationSuper args).overrideAttrs (args: { - NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static"; + else (mkDerivationSuper args).overrideAttrs (args: if args ? env.NIX_CFLAGS_LINK then { + env = args.env // { + NIX_CFLAGS_LINK = toString args.env.NIX_CFLAGS_LINK + " -static"; + }; + } else { + NIX_CFLAGS_LINK = toString (args.env.NIX_CFLAGS_LINK or "") + " -static"; } // lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) { configureFlags = (args.configureFlags or []) ++ [ "--disable-shared" # brrr...