diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index 88ef284fa3b..1a8e584d65f 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -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)]; diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index f6bf73a26fe..72904458665 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -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 diff --git a/pkgs/lib/customisation.nix b/pkgs/lib/customisation.nix new file mode 100644 index 00000000000..889ce04547f --- /dev/null +++ b/pkgs/lib/customisation.nix @@ -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 {}; + }; + + +} diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 2f916d3ddd7..3c760964a28 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -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