[Nix-dev] What does `self` mean in the function `ghcWithPackages`?

Vladimír Čunát vcunat at gmail.com
Tue Dec 16 12:01:51 CET 2014


Hi.

On 12/16/2014 03:30 AM, Carlo Nucera wrote:
> In the line `packages = pkgs self;` what does `self` refer to?

Obviously, ``self`` is the parameter of the whole haskell-packages.nix 
top-level function (line 58 in recent master version).

> I gather that pkgs, the value we should pass to ghcWithPackages, has
> to be a function, to be called on self;
> but what should this function do?

For a practical example see e.g.
https://nixos.org/wiki/Haskell#Local_use_via_myEnvFun

An attempt to explain what is ``self`` good for:

When constructing the haskell package attrmaps, you shouldn't use direct 
references to packages, but access them through the ``self`` attrmap. 
That is a standard (lazy-eval) mechanism for modifiable constructs. You 
construct the final result by composing parts, perhaps applying 
additional modifications to base expressions. In order for the parts to 
have access to these "external" changes, you pass the *final* result to 
each of the parts (result is called ``self`` here; laziness is needed to 
do that).


Vladimir


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3251 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20141216/1c86d0c3/attachment.bin 


More information about the nix-dev mailing list