From 77493367043ce3139656e6abf7314cdd5f984a41 Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 12 May 2025 13:48:39 -0400 Subject: [PATCH 1/6] stdenv.mkDerivation: warn when overriding version without also overriding src With the addition of `finalAttrs`, lots of packages have started to use this pattern: ``` stdenv.mkDerivation (finalAttrs: { version = "1.0.0"; src = fetchurl { url = "https://example.com/foo/${finalAttrs.version}.tar.gz"; }; }) ``` in the hopes that when a user overrides `version` with `overrideAttrs`, the source's URL will get modified too. Unfortunately, this doesn't have any effect due to how most of our FODs are named, basically behaving no differently to using `rec` in package definitions to reuse attributes. This change hopes to improve the user experience a bit by adding a warning when `overrideAttrs` is used in this way, which will help no matter if the package is using `finalAttrs` or `rec`. --- pkgs/stdenv/generic/make-derivation.nix | 43 ++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 8ecdb6879740..cf7917f366a9 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -87,7 +87,48 @@ let args = rattrs (args // { inherit finalPackage overrideAttrs; }); # ^^^^ - overrideAttrs = f0: makeDerivationExtensible (lib.extends (lib.toExtension f0) rattrs); + overrideAttrs = + f0: + let + extends' = + overlay: f: + ( + final: + let + prev = f final; + thisOverlay = overlay final prev; + warnForBadVersionOverride = ( + thisOverlay ? version + && !(thisOverlay ? src) + && !(thisOverlay.__intentionallyOverridingVersion or false) + ); + pname = args.pname or ""; + version = args.version or ""; + pos = builtins.unsafeGetAttrPos "version" thisOverlay; + in + lib.warnIf warnForBadVersionOverride '' + ${ + args.name or "${pname}-${version}" + } was overridden with `version` but not `src` at ${pos.file or ""}:${ + builtins.toString pos.line or "" + }:${builtins.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: + + 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.) + '' (prev // (builtins.removeAttrs thisOverlay [ "__intentionallyOverridingVersion" ])) + ); + in + makeDerivationExtensible (extends' (lib.toExtension f0) rattrs); finalPackage = mkDerivationSimple overrideAttrs args; From eb7c5d11cd4f8a5b6e3a16ee47d62e5b651775ca Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 12 May 2025 16:48:21 -0400 Subject: [PATCH 2/6] bolt-launcher: silence false positive overrideAttrs warning --- pkgs/by-name/bo/bolt-launcher/package.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/bo/bolt-launcher/package.nix b/pkgs/by-name/bo/bolt-launcher/package.nix index 6c6466acc1aa..f2c01aceb329 100644 --- a/pkgs/by-name/bo/bolt-launcher/package.nix +++ b/pkgs/by-name/bo/bolt-launcher/package.nix @@ -23,6 +23,7 @@ let cef = cef-binary.overrideAttrs (oldAttrs: { version = "126.2.18"; + __intentionallyOverridingVersion = true; # `cef-binary` uses the overridden `srcHash` values in its source FOD gitRevision = "3647d39"; chromiumVersion = "126.0.6478.183"; From 350e41e155ff95457309414e417fba9f83b9c4a6 Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 12 May 2025 16:55:49 -0400 Subject: [PATCH 3/6] neovimUtils.buildNeovimPlugin: silence false positive overrideAttrs warning --- pkgs/applications/editors/neovim/build-neovim-plugin.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/applications/editors/neovim/build-neovim-plugin.nix b/pkgs/applications/editors/neovim/build-neovim-plugin.nix index 18e1c550ade5..fece233768af 100644 --- a/pkgs/applications/editors/neovim/build-neovim-plugin.nix +++ b/pkgs/applications/editors/neovim/build-neovim-plugin.nix @@ -26,6 +26,7 @@ let luaDrv = originalLuaDrv.overrideAttrs (oa: { version = attrs.version or oa.version; + __intentionallyOverridingVersion = true; rockspecVersion = oa.rockspecVersion; extraConfig = '' @@ -43,6 +44,7 @@ let lua.pkgs.luarocksMoveDataFolder ]; version = "${originalLuaDrv.version}-unstable-${oa.version}"; + __intentionallyOverridingVersion = true; } ) ); From ac8413565545c9894c9c139bdc317e1662d0a9d4 Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 12 May 2025 16:59:45 -0400 Subject: [PATCH 4/6] luaPackages.cqueues: silence false positive overrideAttrs warning --- pkgs/development/lua-modules/overrides.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/lua-modules/overrides.nix b/pkgs/development/lua-modules/overrides.nix index d28301530344..d51b7c42474b 100644 --- a/pkgs/development/lua-modules/overrides.nix +++ b/pkgs/development/lua-modules/overrides.nix @@ -111,6 +111,7 @@ in rev = lib.last (lib.splitString "-" (lib.last rel)); in "${date}-${rev}"; + __intentionallyOverridingVersion = true; meta.broken = luaOlder "5.1" || luaAtLeast "5.5"; From 1de5fb50b066390e876565e0fb94815dbe869e2e Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 12 May 2025 17:23:37 -0400 Subject: [PATCH 5/6] obs-studio: silence false positive overrideAttrs warning --- pkgs/applications/video/obs-studio/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/applications/video/obs-studio/default.nix b/pkgs/applications/video/obs-studio/default.nix index f3ddf8f24ae8..85619d66e647 100644 --- a/pkgs/applications/video/obs-studio/default.nix +++ b/pkgs/applications/video/obs-studio/default.nix @@ -67,6 +67,7 @@ let cef = cef-binary.overrideAttrs (oldAttrs: { version = "127.3.5"; + __intentionallyOverridingVersion = true; # `cef-binary` uses the overridden `srcHash` values in its source FOD gitRevision = "114ea2a"; chromiumVersion = "127.0.6533.120"; From 2a4e829d7bc43ed9b2cc2eb5d6867d96a52fb4e4 Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 12 May 2025 17:29:18 -0400 Subject: [PATCH 6/6] linux-wallpaperengine: silence false positive overrideAttrs warning --- pkgs/by-name/li/linux-wallpaperengine/package.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/li/linux-wallpaperengine/package.nix b/pkgs/by-name/li/linux-wallpaperengine/package.nix index defcbe97676d..5dfee0f92ad5 100644 --- a/pkgs/by-name/li/linux-wallpaperengine/package.nix +++ b/pkgs/by-name/li/linux-wallpaperengine/package.nix @@ -33,6 +33,7 @@ let cef = cef-binary.overrideAttrs (oldAttrs: { version = "120.1.10"; + __intentionallyOverridingVersion = true; # `cef-binary` uses the overridden `srcHash` values in its source FOD gitRevision = "3ce3184"; chromiumVersion = "120.0.6099.129";