[Nix-dev] Re: [Nix-commits] SVN commit: nix - 18466 - eelco - in nixpkgs/trunk/pkgs: build-support/vm lib

Lluís Batlle viriketo at gmail.com
Fri Nov 20 11:27:17 CET 2009


The usage of overrideDerivation with the
super-stdenv-allowing-cross-compilation may be a bit confusing. The
final "buildInputs" and "buildNativeInputs" finally used as parameters
for the "derivation" are changed from those passed to "mkDerivation",
according to the cross or native compilation.
Let me remind that while we maintain functionality, we still have all
namings and plays under debate.

overrideDerivation should be used attenting on what play is done in
the attributes passed to mkDerivation, and how they map to the
attributes passed to derivation. And even for a simpler example,
imagine a user wrote a unpackPhase relying on "${src}" instead of
"$src"... then overriding the src through overrideDerivation would not
change the unpackPhase. Right?

Regards,
Lluís.

2009/11/19 Eelco Dolstra <e.dolstra at tudelft.nl>:
> Author: eelco
> Date: 2009-11-19 16:43:58 +0000 (Thu, 19 Nov 2009)
> New Revision: 18466
>
> You can view the changes in this commit at:
>   https://svn.nixos.org/viewvc/nix?rev=18466&view=rev
>
> Added:
>   nixpkgs/trunk/pkgs/lib/customisation.nix
> Modified:
>   nixpkgs/trunk/pkgs/build-support/vm/default.nix
>   nixpkgs/trunk/pkgs/lib/attrsets.nix
>   nixpkgs/trunk/pkgs/lib/default.nix
>
> Log:
> * Move `modifyDerivation' from build-support/vm to lib and rename it
>  to `overrideDerivation'.
>
>
> Changes:
>
> Modified: nixpkgs/trunk/pkgs/build-support/vm/default.nix
> ===================================================================
> --- nixpkgs/trunk/pkgs/build-support/vm/default.nix     2009-11-19 16:07:47 UTC (rev 18465)
> +++ nixpkgs/trunk/pkgs/build-support/vm/default.nix     2009-11-19 16:43:58 UTC (rev 18466)
> @@ -252,15 +252,6 @@
>   '';
>
>
> -  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 @@
>      `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 @@
>      - 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)];
>
> Modified: nixpkgs/trunk/pkgs/lib/attrsets.nix
> ===================================================================
> --- nixpkgs/trunk/pkgs/lib/attrsets.nix 2009-11-19 16:07:47 UTC (rev 18465)
> +++ nixpkgs/trunk/pkgs/lib/attrsets.nix 2009-11-19 16:43:58 UTC (rev 18466)
> @@ -13,7 +13,7 @@
>
>   /* 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
>
> Added: nixpkgs/trunk/pkgs/lib/customisation.nix
> ===================================================================
> --- nixpkgs/trunk/pkgs/lib/customisation.nix                            (rev 0)
> +++ nixpkgs/trunk/pkgs/lib/customisation.nix    2009-11-19 16:43:58 UTC (rev 18466)
> @@ -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 {};
> +      };
> +
> +
> +}
>
> Modified: nixpkgs/trunk/pkgs/lib/default.nix
> ===================================================================
> --- nixpkgs/trunk/pkgs/lib/default.nix  2009-11-19 16:07:47 UTC (rev 18465)
> +++ nixpkgs/trunk/pkgs/lib/default.nix  2009-11-19 16:43:58 UTC (rev 18466)
> @@ -15,6 +15,7 @@
>   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 @@
>   # commonly used functions.
>   // trivial // lists // strings // stringsWithDeps // attrsets // sources
>   // properties // options // types // meta // debug // misc // modules
> +  // customisation
>
> _______________________________________________
> nix-commits mailing list
> nix-commits at cs.uu.nl
> http://mail.cs.uu.nl/mailman/listinfo/nix-commits
>



More information about the nix-dev mailing list