From 7146b6678f02fe43d30747a75a45d5cd1f50e63e Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Thu, 28 May 2026 00:14:04 -0400 Subject: [PATCH 1/4] stdenv.mkDerivation: remove warnIf usage warnIf sends our warning message through a function call, even if the warning condition doesn't trigger. This requires a lot of thunk allocation that can be easily avoided. --- pkgs/stdenv/generic/make-derivation.nix | 54 +++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index fb61ade7e4e3..a010f8d3ec34 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -128,8 +128,8 @@ let # f is not a function; probably { ... } f0; in - warnIf - ( + ( + if prev ? src && thisOverlay ? version && prev ? version @@ -138,32 +138,36 @@ let # && prev.version != thisOverlay.version && !(thisOverlay ? src) && !(thisOverlay.__intentionallyOverridingVersion or false) - ) - ( - let - pos = unsafeGetAttrPos "version" thisOverlay; - in - '' - ${ - args.name or "${args.pname or ""}-${args.version or ""}" - } was overridden with `version` but not `src` at ${pos.file or ""}:${ - toString pos.line or "" - }:${toString pos.column or ""}. - This is most likely not what you want. In order to properly change the version of a package, override - both the `version` and `src` attributes: + then + warn ( + let + pos = unsafeGetAttrPos "version" thisOverlay; + in + '' + ${ + args.name or "${args.pname or ""}-${args.version or ""}" + } was overridden with `version` but not `src` at ${pos.file or ""}:${ + toString pos.line or "" + }:${toString pos.column or ""}. - hello.overrideAttrs (oldAttrs: rec { - version = "1.0.0"; - src = pkgs.fetchurl { - url = "mirror://gnu/hello/hello-''${version}.tar.gz"; - hash = "..."; - }; - }) + This is most likely not what you want. In order to properly change the version of a package, override + both the `version` and `src` attributes: - (To silence this warning, set `__intentionallyOverridingVersion = true` in your `overrideAttrs` call.) - '' - ) + hello.overrideAttrs (oldAttrs: rec { + version = "1.0.0"; + src = pkgs.fetchurl { + url = "mirror://gnu/hello/hello-''${version}.tar.gz"; + hash = "..."; + }; + }) + + (To silence this warning, set `__intentionallyOverridingVersion = true` in your `overrideAttrs` call.) + '' + ) + else + x: x + ) (prev // (removeAttrs thisOverlay [ "__intentionallyOverridingVersion" ])) ); From 3ec1e90b1069a9baad558fb1c988191ccd4f6c36 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Thu, 28 May 2026 00:15:16 -0400 Subject: [PATCH 2/4] lib/modules: remove warnIf usage warnIf sends our warning message through a function call, even if the warning condition doesn't trigger. This requires a lot of thunk allocation that can be easily avoided. --- lib/modules.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 1adee44f7a33..2820aa921bf2 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -1158,8 +1158,10 @@ let value = if opt ? apply then opt.apply res.mergedValue else res.mergedValue; warnDeprecation = - warnIf (opt.type.deprecationMessage != null) - "The type `types.${opt.type.name}' of option `${showOption loc}' defined in ${showFiles opt.declarations} is deprecated. ${opt.type.deprecationMessage}"; + if (opt.type.deprecationMessage != null) then + warn "The type `types.${opt.type.name}' of option `${showOption loc}' defined in ${showFiles opt.declarations} is deprecated. ${opt.type.deprecationMessage}" + else + x: x; in warnDeprecation opt From 020ce4ae440314c96c3e90569ff95e2e5b348de8 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Thu, 28 May 2026 00:15:36 -0400 Subject: [PATCH 3/4] build-support/fetchzip: remove warnIf usage warnIf sends our warning message through a function call, even if the warning condition doesn't trigger. This requires a lot of thunk allocation that can be easily avoided. --- pkgs/build-support/fetchzip/default.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index 4376fef41085..4878ece47f76 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -106,9 +106,11 @@ lib.extendMkDerivation { ) + '' ${postFetch} - ${lib.warnIf (extraPostFetch != "") - "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub' or 'fetchFromGitLab'." - extraPostFetch + ${ + if extraPostFetch != "" then + lib.warn "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub' or 'fetchFromGitLab'." extraPostFetch + else + extraPostFetch } chmod 755 "$out" ''; From 28e6e36fa01c0037066e81385c280989bf95d455 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Thu, 28 May 2026 00:15:41 -0400 Subject: [PATCH 4/4] build-support/fetchurl: remove warnIf usage warnIf sends our warning message through a function call, even if the warning condition doesn't trigger. This requires a lot of thunk allocation that can be easily avoided. --- pkgs/build-support/fetchurl/default.nix | 38 ++++++++++++++----------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index 2f75079ead55..0d626d5783f9 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -327,23 +327,27 @@ lib.extendMkDerivation { outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; - curlOpts = lib.warnIf (lib.isList curlOpts) ( - let - url = toString (builtins.head urls_); - curlOptsRepresentation = lib.generators.toPretty { multiline = false; } curlOpts; - curlOptsAsStringRepresentation = lib.strings.escapeNixString (toString curlOpts); - curlOptsListElementsRepresentation = - lib.concatMapStringsSep " " lib.strings.escapeNixString - curlOpts; - in - '' - fetchurl for ${url}: curlOpts is a list (${curlOptsRepresentation}), which is not supported anymore. - - If you wish to get the same effect as before, for elements with spaces (even if escaped) to expand to multiple curl arguments, use a string argument instead: - curlOpts = ${curlOptsAsStringRepresentation}; - - If you wish for each list element to be passed as a separate curl argument, allowing arguments to contain spaces, use curlOptsList instead: - curlOptsList = [ ${curlOptsListElementsRepresentation} ]; - '' - ) curlOpts; + curlOpts = + if lib.isList curlOpts then + lib.warn ( + let + url = toString (builtins.head urls_); + curlOptsRepresentation = lib.generators.toPretty { multiline = false; } curlOpts; + curlOptsAsStringRepresentation = lib.strings.escapeNixString (toString curlOpts); + curlOptsListElementsRepresentation = + lib.concatMapStringsSep " " lib.strings.escapeNixString + curlOpts; + in + '' + fetchurl for ${url}: curlOpts is a list (${curlOptsRepresentation}), which is not supported anymore. + - If you wish to get the same effect as before, for elements with spaces (even if escaped) to expand to multiple curl arguments, use a string argument instead: + curlOpts = ${curlOptsAsStringRepresentation}; + - If you wish for each list element to be passed as a separate curl argument, allowing arguments to contain spaces, use curlOptsList instead: + curlOptsList = [ ${curlOptsListElementsRepresentation} ]; + '' + ) curlOpts + else + curlOpts; inherit curlOptsList