* Move `modifyDerivation' from build-support/vm to lib and rename it

to `overrideDerivation'.

svn path=/nixpkgs/trunk/; revision=18466
This commit is contained in:
Eelco Dolstra 2009-11-19 16:43:58 +00:00
parent aa392c3aa7
commit 519e7870b6
4 changed files with 45 additions and 12 deletions

View File

@ -252,15 +252,6 @@ rec {
'';
modifyDerivation = f: attrs:
let attrsCleaned = removeAttrs attrs ["meta" "passthru" "outPath" "drvPath"];
newDrv = derivation (attrsCleaned // (f attrs));
in newDrv //
{ meta = if attrs ? meta then attrs.meta else {};
passthru = if attrs ? passthru then attrs.passthru else {};
};
/* Run a derivation in a Linux virtual machine (using Qemu/KVM). By
default, there is no disk image; the root filesystem is a tmpfs,
and /nix/store is shared with the host (via the CIFS protocol to
@ -282,7 +273,7 @@ rec {
`run-vm' will be left behind in the temporary build directory
that allows you to boot into the VM and debug it interactively. */
runInLinuxVM = modifyDerivation (attrs: {
runInLinuxVM = drv: lib.overrideDerivation drv (attrs: {
builder = "${bash}/bin/sh";
args = ["-e" (vmRunCommand qemuCommandLinux)];
origArgs = attrs.args;
@ -317,7 +308,7 @@ rec {
- Reboot to shutdown the machine (because Qemu doesn't seem
capable of a APM/ACPI VM shutdown).
*/
runInGenericVM = modifyDerivation (attrs: {
runInGenericVM = drv: lib.overrideDerivation drv (attrs: {
system = "i686-linux";
builder = "${bash}/bin/sh";
args = ["-e" (vmRunCommand qemuCommandGeneric)];

View File

@ -13,7 +13,7 @@ rec {
/* Return an attribute from nested attribute sets. For instance
["x" "y"] applied to some set e returns e.x.y, if it exists. The
default value is returned otherwise. */
default value is returned otherwise. */
attrByPath = attrPath: default: e:
let attr = head attrPath;
in

View File

@ -0,0 +1,40 @@
{
/* `overrideDerivation drv f' takes a derivation (i.e., the result
of a call to the builtin function `derivation') and returns a new
derivation in which the attributes of the original are overriden
according to the function `f'. This function is called with the
original derivation attributes.
`overrideDerivation' allows certain "ad-hoc" customisation
scenarios (e.g. in ~/.nixpkgs/config.nix). For instance, if you
want to "patch" the derivation returned by a package function in
Nixpkgs to build another version than what the function itself
provides, you can do something like this:
mySed = overrideDerivation pkgs.gnused (oldAttrs: {
name = "sed-4.2.2-pre";
src = fetchurl {
url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k";
};
patches = [];
});
For another application, see build-support/vm, where this
function is used to build arbitrary derivations inside a QEMU
virtual machine. */
overrideDerivation = drv: f:
let
# Filter out special attributes.
attrs = removeAttrs drv ["meta" "passthru" "outPath" "drvPath"];
newDrv = derivation (attrs // (f drv));
in newDrv //
{ meta = if drv ? meta then drv.meta else {};
passthru = if drv ? passthru then drv.passthru else {};
};
}

View File

@ -15,6 +15,7 @@ let
misc = import ./misc.nix;
maintainers = import ./maintainers.nix;
platforms = import ./platforms.nix;
customisation = import ./customisation.nix;
in
{ inherit trivial lists strings stringsWithDeps attrsets sources options
@ -24,3 +25,4 @@ in
# commonly used functions.
// trivial // lists // strings // stringsWithDeps // attrsets // sources
// properties // options // types // meta // debug // misc // modules
// customisation