From 00b9996c9ad5726c49dfdb0974a75fe7a2f03b0a Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 3 Aug 2024 23:10:26 +1200 Subject: [PATCH] stdenv: Take nested env.NIX_CFLAGS_LINK into account when making static binaries https://github.com/NixOS/nixpkgs/pull/315998/files#diff-2828f66a476875b1160e3c241960db085c2a3933211cc187bcd1fb456fb95e7fL213-R216 moved NIX_CFLAGS_LINK from a top-level `mkDerivation` argument to the nested `env` attribute. This doesn't play nicely with how `stdenv/adapters.nix` adds it's NIX_CFLAGS_LINK in the top-level. This changes the stdenv adapter to check for the presence of `env.NIX_CFLAGS_LINK`, and override that one if present, and only otherwise override on the top-level drv attrset. --- pkgs/stdenv/adapters.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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...