Skip to content

Commit 0ca4e5f

Browse files
authored
stdenv.mkDerivation: warn when overriding version without also overriding src (#406535)
2 parents e48f0a0 + 2a4e829 commit 0ca4e5f

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

pkgs/applications/editors/neovim/build-neovim-plugin.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ let
2626

2727
luaDrv = originalLuaDrv.overrideAttrs (oa: {
2828
version = attrs.version or oa.version;
29+
__intentionallyOverridingVersion = true;
2930
rockspecVersion = oa.rockspecVersion;
3031

3132
extraConfig = ''
@@ -43,6 +44,7 @@ let
4344
lua.pkgs.luarocksMoveDataFolder
4445
];
4546
version = "${originalLuaDrv.version}-unstable-${oa.version}";
47+
__intentionallyOverridingVersion = true;
4648
}
4749
)
4850
);

pkgs/applications/video/obs-studio/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ let
6767

6868
cef = cef-binary.overrideAttrs (oldAttrs: {
6969
version = "127.3.5";
70+
__intentionallyOverridingVersion = true; # `cef-binary` uses the overridden `srcHash` values in its source FOD
7071
gitRevision = "114ea2a";
7172
chromiumVersion = "127.0.6533.120";
7273

pkgs/by-name/bo/bolt-launcher/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
let
2424
cef = cef-binary.overrideAttrs (oldAttrs: {
2525
version = "126.2.18";
26+
__intentionallyOverridingVersion = true; # `cef-binary` uses the overridden `srcHash` values in its source FOD
2627
gitRevision = "3647d39";
2728
chromiumVersion = "126.0.6478.183";
2829

pkgs/by-name/li/linux-wallpaperengine/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
let
3434
cef = cef-binary.overrideAttrs (oldAttrs: {
3535
version = "120.1.10";
36+
__intentionallyOverridingVersion = true; # `cef-binary` uses the overridden `srcHash` values in its source FOD
3637
gitRevision = "3ce3184";
3738
chromiumVersion = "120.0.6099.129";
3839

pkgs/development/lua-modules/overrides.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ in
109109
rev = lib.last (lib.splitString "-" (lib.last rel));
110110
in
111111
"${date}-${rev}";
112+
__intentionallyOverridingVersion = true;
112113

113114
meta.broken = luaOlder "5.1" || luaAtLeast "5.5";
114115

pkgs/stdenv/generic/make-derivation.nix

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,48 @@ let
8787
args = rattrs (args // { inherit finalPackage overrideAttrs; });
8888
# ^^^^
8989

90-
overrideAttrs = f0: makeDerivationExtensible (lib.extends (lib.toExtension f0) rattrs);
90+
overrideAttrs =
91+
f0:
92+
let
93+
extends' =
94+
overlay: f:
95+
(
96+
final:
97+
let
98+
prev = f final;
99+
thisOverlay = overlay final prev;
100+
warnForBadVersionOverride = (
101+
thisOverlay ? version
102+
&& !(thisOverlay ? src)
103+
&& !(thisOverlay.__intentionallyOverridingVersion or false)
104+
);
105+
pname = args.pname or "<unknown name>";
106+
version = args.version or "<unknown version>";
107+
pos = builtins.unsafeGetAttrPos "version" thisOverlay;
108+
in
109+
lib.warnIf warnForBadVersionOverride ''
110+
${
111+
args.name or "${pname}-${version}"
112+
} was overridden with `version` but not `src` at ${pos.file or "<unknown file>"}:${
113+
builtins.toString pos.line or "<unknown line>"
114+
}:${builtins.toString pos.column or "<unknown column>"}.
115+
116+
This is most likely not what you want. In order to properly change the version of a package, override
117+
both the `version` and `src` attributes:
118+
119+
hello.overrideAttrs (oldAttrs: rec {
120+
version = "1.0.0";
121+
src = pkgs.fetchurl {
122+
url = "mirror://gnu/hello/hello-''${version}.tar.gz";
123+
hash = "...";
124+
};
125+
})
126+
127+
(To silence this warning, set `__intentionallyOverridingVersion = true` in your `overrideAttrs` call.)
128+
'' (prev // (builtins.removeAttrs thisOverlay [ "__intentionallyOverridingVersion" ]))
129+
);
130+
in
131+
makeDerivationExtensible (extends' (lib.toExtension f0) rattrs);
91132

92133
finalPackage = mkDerivationSimple overrideAttrs args;
93134

0 commit comments

Comments
 (0)