replace-dependency: Eelco has ruled, lowerCamelCase > dash-case :(

This commit is contained in:
Shea Levy 2013-01-13 11:15:01 -05:00
parent 4dc4d10123
commit 553e1b16f0
2 changed files with 20 additions and 20 deletions

View File

@ -8,16 +8,16 @@
# should be used. The old dependency and new dependency MUST have the same-length # should be used. The old dependency and new dependency MUST have the same-length
# name, and ideally should have close-to-identical directory layout. # name, and ideally should have close-to-identical directory layout.
# #
# Example: safe-firefox = replace-dependency { # Example: safeFirefox = replaceDependency {
# drv = firefox; # drv = firefox;
# old-dependency = glibc; # oldDependency = glibc;
# new-dependency = overrideDerivation glibc (attrs: { # newDependency = overrideDerivation glibc (attrs: {
# patches = attrs.patches ++ [ ./fix-glibc-hole.patch ]; # patches = attrs.patches ++ [ ./fix-glibc-hole.patch ];
# }); # });
# }; # };
# This will rebuild glibc with your security patch, then copy over firefox # This will rebuild glibc with your security patch, then copy over firefox
# (and all of its dependencies) without rebuilding further. # (and all of its dependencies) without rebuilding further.
{ drv, old-dependency, new-dependency }: { drv, oldDependency, newDependency }:
with lib; with lib;
@ -45,17 +45,17 @@ let
discard = builtins.unsafeDiscardStringContext; discard = builtins.unsafeDiscardStringContext;
old-storepath = builtins.storePath (discard (toString old-dependency)); oldStorepath = builtins.storePath (discard (toString oldDependency));
references-of = drv: getAttr (discard (toString drv)) references; referencesOf = drv: getAttr (discard (toString drv)) references;
depends-on-old = drv: elem old-storepath (references-of drv) || dependsOnOld = drv: elem oldStorepath (referencesOf drv) ||
any depends-on-old (references-of drv); any dependsOnOld (referencesOf drv);
drv-name = drv: drvName = drv:
discard (substring 33 (stringLength (builtins.baseNameOf drv)) (builtins.baseNameOf drv)); discard (substring 33 (stringLength (builtins.baseNameOf drv)) (builtins.baseNameOf drv));
rewrite-hashes = drv: hashes: runCommand (drv-name drv) { nixStore = "${nix}/bin/nix-store"; } '' rewriteHashes = drv: hashes: runCommand (drvName drv) { nixStore = "${nix}/bin/nix-store"; } ''
$nixStore --dump ${drv} | sed 's|${baseNameOf drv}|'$(basename $out)'|g' | sed -e ${ $nixStore --dump ${drv} | sed 's|${baseNameOf drv}|'$(basename $out)'|g' | sed -e ${
concatStringsSep " -e " (mapAttrsToList (name: value: concatStringsSep " -e " (mapAttrsToList (name: value:
"'s|${baseNameOf name}|${baseNameOf value}|g'" "'s|${baseNameOf name}|${baseNameOf value}|g'"
@ -63,17 +63,17 @@ let
} | $nixStore --restore $out } | $nixStore --restore $out
''; '';
rewritten-deps = listToAttrs [ {name = discard (toString old-dependency); value = new-dependency;} ]; rewrittenDeps = listToAttrs [ {name = discard (toString oldDependency); value = newDependency;} ];
rewritten-derivations = drv: rewrittenDerivations = drv:
if depends-on-old drv if dependsOnOld drv
then listToAttrs [ { then listToAttrs [ {
name = discard (toString drv); name = discard (toString drv);
value = rewrite-hashes drv (rewritten-deps // (fold (drv: acc: value = rewriteHashes drv (rewrittenDeps // (fold (drv: acc:
(rewritten-derivations drv) // acc (rewrittenDerivations drv) // acc
) {} (references-of drv))); ) {} (referencesOf drv)));
} ] } ]
else {}; else {};
in assert (stringLength (drv-name (toString old-dependency)) == stringLength (drv-name (toString new-dependency))); in assert (stringLength (drvName (toString oldDependency)) == stringLength (drvName (toString newDependency)));
getAttr (discard (toString drv)) (rewritten-derivations drv) getAttr (discard (toString drv)) (rewrittenDerivations drv)

View File

@ -344,9 +344,9 @@ let
inherit stdenv; inherit stdenv;
}; };
"replace-dependency" = if builtins ? langVersion then import ../build-support/replace-dependency.nix { replaceDependency = import ../build-support/replace-dependency.nix {
inherit runCommand nix lib; inherit runCommand nix lib;
} else args: throw "You must be using at least nix-1.2 to use replace-dependency"; };
nukeReferences = callPackage ../build-support/nuke-references/default.nix { }; nukeReferences = callPackage ../build-support/nuke-references/default.nix { };