From 7ba63c64a628e99893dedf837f6291cecc5798bb Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Fri, 19 Dec 2025 22:23:47 +0800 Subject: [PATCH] testers.invalidateFetcherByDrvHash: use overrideAttrs if fetcher ignore name arguments --- pkgs/build-support/testers/default.nix | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index f82c41c7fe5b..6b33c4d2077e 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -132,7 +132,8 @@ invalidateFetcherByDrvHash = f: args: let - drvPath = (f args).drvPath; + unsalted = f args; + drvPath = unsalted.drvPath; # It's safe to discard the context, because we don't access the path. salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath)); saltName = name: "${name}-salted-${salt}"; @@ -143,14 +144,23 @@ else { name = saltName args.name or "source"; }; # New derivation incorporating the original drv hash in the name - salted = f (args // getSaltedNames args); - # Make sure we did change the derivation. If the fetcher ignores `name`, + saltedByArgs = f (args // getSaltedNames args); + saltedByOverrideAttrs = unsalted.overrideAttrs (previousAttrs: getSaltedNames previousAttrs); + saltedByOverrideAttrsForced = unsalted.overrideAttrs (previousAttrs: { + name = saltName unsalted.name; + }); + # Make sure we did change the derivation. + # If the fetcher ignores `pname` and `name` and provide a broken `overrideAttrs`, # `invalidateFetcherByDrvHash` doesn't work. checked = - if salted.drvPath == drvPath then - throw "invalidateFetcherByDrvHash: Adding the derivation hash to the fixed-output derivation name had no effect. Make sure the fetcher's name argument ends up in the derivation name. Otherwise, the fetcher will not be re-run when its implementation changes. This is important for testing." + if saltedByArgs.drvPath != drvPath then + saltedByArgs + else if saltedByOverrideAttrs.drvPath != drvPath then + saltedByOverrideAttrs + else if saltedByOverrideAttrsForced.drvPath != drvPath then + saltedByOverrideAttrsForced else - salted; + throw "invalidateFetcherByDrvHash: Neither adding pname/name to the fetcher args nor overriding with overrideAttrs change the result drvPath."; in checked;