From 5d7df1597d339cd74bf93eb7637e90e7029fb343 Mon Sep 17 00:00:00 2001 From: eyjhb Date: Thu, 22 Oct 2026 12:08:26 +0200 Subject: [PATCH] replaceDependencies: only resolve newDependency if drv depends on it Flips the if statements in relevantReplacements, so that newDependency is only evailuated if drv depends on oldDependency it replaces. --- pkgs/build-support/replace-dependencies.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/replace-dependencies.nix b/pkgs/build-support/replace-dependencies.nix index 2d449dcee1af..7e93098374f8 100644 --- a/pkgs/build-support/replace-dependencies.nix +++ b/pkgs/build-support/replace-dependencies.nix @@ -123,17 +123,17 @@ let rootReferences = referencesOf drv; relevantReplacements = filter ( { oldDependency, newDependency }: - if toString oldDependency == toString newDependency then - warn "replaceDependencies: attempting to replace dependency ${oldDependency} of ${drv} with itself" - # Attempting to replace a dependency by itself is completely useless, and would only lead to infinite recursion. - # Hence it must not be attempted to apply this replacement in any case. - false - else if !hasAttr (realisation oldDependency) rootReferences then + if !hasAttr (realisation oldDependency) rootReferences then warn "replaceDependencies: ${drv} does not depend on ${oldDependency}, so it will not be replaced" # Strictly speaking, another replacement could introduce the dependency. # However, handling this corner case would add significant complexity. # So we just leave it to the user to apply the replacement at the correct place, but show a warning to let them know. false + else if toString oldDependency == toString newDependency then + warn "replaceDependencies: attempting to replace dependency ${oldDependency} of ${drv} with itself" + # Attempting to replace a dependency by itself is completely useless, and would only lead to infinite recursion. + # Hence it must not be attempted to apply this replacement in any case. + false else true ) replacements;