Skip to content

Commit

Permalink
nixos/top-level: improve replaceRuntimeDependencies
Browse files Browse the repository at this point in the history
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: NixOS#4336
  • Loading branch information
alois31 committed Sep 25, 2023
1 parent 91a266c commit 1940199
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nixos/modules/system/activation/top-level.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]; };
Expand Down

0 comments on commit 1940199

Please sign in to comment.