[Nix-dev] Override Sets in an Environment

Benno Fünfstück benno.fuenfstueck at gmail.com
Fri Aug 21 21:58:11 CEST 2015


The problem is in the following line:

  hpkgs = pkgs.haskell.packages.${compiler} // { aeson =
pkgs.haskell.packages.${compiler}.callPackage ./aeson-0.8.0.2.nix {}; };

This line will not do what you expect. It will only override the `aeson`
member of the set, all packages that depend on aeson will continue to
depend on the old version though! Also, `callPackage` will continue to
refer to the old `aeson`, because it's just a simple function, there is no
way that it can see what else you changed about the set. The "environment"
that `callPackage` uses to look up package names is also often called the
scope. Your approach doesn't change the scope.

Instead, the proper way to override haskell packages is:

  mpkgs = pkgs.haskell.packages.${compiler}.override {
    overrides = self: super: {
      aeson = self.callPackage ./aeson-0.8.0.2.nix {};
      my-pack = self.callPackage ./. {};
    };

The .override function makes sure that the whole haskell package set is
reevaluated, taking the overriden scope into account, so packages that
depend on aeson will see the "new" aeson package.

Regards,
Benno

Oliver Dunkl <oliver.dunkl at gmail.com> schrieb am Do., 20. Aug. 2015 um
09:57 Uhr:

> I would like to override a set of Haskell packages in a nix-shell. I
> tested it in a nix-repl with
>
> nix-repl> :l <nixpkgs>
> nix-repl> hpkgs = pkgs.haskell.packages.ghc784 // { aeson =
> pkgs.haskell.packages.ghc784.callPackage ./aeson-0.8.0.2.nix {}; }
> nix-repl> pkgs.haskell.packages.ghc784.aeson.version
> "0.9.0.1"
> nix-repl> hpkgs.aeson.version
> "0.8.0.2"
>
> Thats ok!
>
> Now I have a shell.nix and want to load all that stuff into a
> nix-shell. My shell.nix looks like
>
> { nixpkgs ? import <nixpkgs> {}, compiler ? "ghc784" }:
> let
>   inherit (nixpkgs) pkgs;
>
>   hpkgs = pkgs.haskell.packages.${compiler} // { aeson =
> pkgs.haskell.packages.${compiler}.callPackage ./aeson-0.8.0.2.nix {}; };
>   mpkgs = hpkgs.override {
>     overrides = self: super: {
>       my-pack = self.callPackage ./. {};
>     };
>   };
> in if pkgs.lib.isNixShell then mpkgs.my-pack.env else mpkgs
>
> My expectation is that I have aeson-0.8.0.2 in my environment but I
> have aeson-0.9.0.1 in it.
>
> nix-shell --command 'ghc-pkg list | grep aeson'
>   aeson-0.9.0.1
>
> Can somebody explain me that behaviour and how to configure
> shell.nix that I have aeson-0.8.0.2 afterwards.
>
> The background is that I would like to make a freeze.nix where all
> libs from the constraints of `cabal freeze' are inside and like to
> override my haskell-packages with that frozen libs.
>
> Nix version 1.9.
>
> thx
> \= odi
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150821/6ec8a659/attachment.html 


More information about the nix-dev mailing list