From 71003837ddbcea5b62136f886e4ff6b393d4de64 Mon Sep 17 00:00:00 2001 From: Stefan Frijters Date: Sun, 8 Mar 2026 22:47:24 +0100 Subject: [PATCH] stdenv: move NIX_CFLAGS_LINK into env by default for makeStaticBinaries This should not depend on whether __structuredAttrs is enabled; it belongs in env regardless. Warn if the flag already exists in the wrong place (which should not be the case in current nixpkgs). --- pkgs/stdenv/adapters.nix | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 93debddba8a1..c5405d6991ae 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -92,16 +92,22 @@ rec { (mkDerivationSuper args).overrideAttrs ( args: ( - if (args.__structuredAttrs or false) || (args ? env.NIX_CFLAGS_LINK) then + if (args ? NIX_CFLAGS_LINK) then + lib.warn + ( + "NIX_CFLAGS_LINK is an environment variable and should be defined inside `env`" + + lib.optionalString (args ? pname) " for package ${args.pname}" + + lib.optionalString (args ? version) "-${args.version}" + ) + { + NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static"; + } + else { env = (args.env or { }) // { NIX_CFLAGS_LINK = toString (args.env.NIX_CFLAGS_LINK or "") + " -static"; }; } - else - { - NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static"; - } ) // lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) { configureFlags = (args.configureFlags or [ ]) ++ [