7 # Replace some direct dependencies of drv, not recursing into the dependency tree.
8 # You likely want to use replaceDependencies instead, unless you plan to implement your own recursion mechanism.
23 if replacements == [ ] then
28 if isStorePath drv then
29 # Reconstruct the name from the actual store path if available.
30 substring 33 (stringLength (baseNameOf drv)) (baseNameOf drv)
31 else if drv ? drvAttrs.name then
32 # Try to get the name from the derivation arguments otherwise (for floating or deferred derivations).
36 outputName = drv.outputName or "out";
38 optionalString (outputName != "out") "-${outputName}"
41 throw "cannot reconstruct the derivation name from ${drv}";
43 runCommandLocal drvName { nativeBuildInputs = [ nix.out ]; } ''
44 createRewriteScript() {
45 while [ $# -ne 0 ]; do
46 oldBasename="$(basename "$1")"
47 newBasename="$(basename "$2")"
49 if [ ''${#oldBasename} -ne ''${#newBasename} ]; then
50 echo "cannot rewrite $oldBasename to $newBasename: length does not match" >&2
53 echo "s|$oldBasename|$newBasename|g" >> rewrite.sed
56 createRewriteScript ${
63 { oldDependency, newDependency }:
71 nix-store --dump ${drv} | sed -f rewrite.sed | nix-store --restore $out