From 1940199f8fdd5e0f977083d99e6d1b09235d2d4d Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sun, 24 Sep 2023 20:52:50 +0200 Subject: [PATCH] nixos/top-level: improve replaceRuntimeDependencies Instead of iterating over all replacements and applying them one by one, use the newly introduced replaceDependencies function to apply them all at once for replaceRuntimeDependencies. The advantages are twofold in case there are multiple replacements: * Performance is significantly improved, because there is only one pass over the closure to be made. * Correctness is improved, because replaceDependencies also replaces dependencies of the replacements themselves if applicable. Fixes: https://github.com/NixOS/nixpkgs/issues/4336 --- nixos/modules/system/activation/top-level.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index 1f9ad570db7d8d4..e19b0ac19f017a9 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -68,9 +68,15 @@ let else showWarnings config.warnings baseSystem; # Replace runtime dependencies - system = foldr ({ oldDependency, newDependency }: drv: - pkgs.replaceDependency { inherit oldDependency newDependency drv; } - ) baseSystemAssertWarn config.system.replaceRuntimeDependencies; + system = let replacements = config.system.replaceRuntimeDependencies; in + if replacements == [] then + # Avoid IFD if possible, by sidestepping replaceDependencies if no replacements are specified. + baseSystemAssertWarn + else + pkgs.replaceDependencies { + drv = baseSystemAssertWarn; + inherit replacements; + }; systemWithBuildDeps = system.overrideAttrs (o: { systemBuildClosure = pkgs.closureInfo { rootPaths = [ system.drvPath ]; };