[Nix-dev] nix-repl / nix-build inconsistency in haskell development

Mateusz Kowalczyk fuuzetsu at fuuzetsu.co.uk
Sun Oct 26 05:12:44 CET 2014


On 10/25/2014 01:39 AM, athan.clark at gmail.com wrote:
> Hello everyone, I'm very new to nix, but I've been working with haskell for
> a little while and have gotten used to cabal sandboxes and the like.
> 
> After looking at a few example packages, I see that the
> <nixpkgs>.pkgs.haskellPackages.cabal.mkDerivation function is traditionally
> used, and it expects a single-parameter function for configuring the
> package to be built.
> 
> I've been following joelteon's nrwhl.org project
> <https://github.com/joelteon/nrwhl.org/blob/master/default.nix> as a
> reference example. Here is mine: http://lpaste.net/113178. When I call
> `nix-build default.nix`, while in my project's directory, I get this
> output: http://lpaste.net/113179.
> 
> My "~/filter" directory looks like this:
> - default.nix
> - filter.cabal
> - src/
> - ...
> 
> The weirdest part for me is that I can actually build everything fine while
> in `nix-repl`! Here is the output I get from doing that:
> http://lpaste.net/113180.
> 
> Where did I mess up? I can't really see what's happening here. Any help
> would be very kind and awesome :)
> 
> Thank you very much!
> 
> 
> 
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
> 

To add to Peter's response, I think you could have avoided the problem
all together simply by using ‘cabal init’ followed by ‘cabal2nix’. This
would ensure you have a Setup.hs and that your ‘default.nix’ is
generated nicely.

The only amendment you'd have to do is to add a shell.nix (because the
generated default.nix doesn't have default arguments). Fortunately this
is easy. Here's an example shell.nix I use for Haddock:

--
let pkgs = import <nixpkgs> {};
    myHaskellPackages = pkgs.myHaskellPackages;
    haskellPackages = myHaskellPackages.override {
      extension = self: super: {
        haddock = myHaskellPackages.callPackage ./. {};
      };
    };
in haskellPackages.haddock
--

The advantage to this approach is that you can freely regenerate your
default.nix with cabal2nix whenever you need to make changes to your
cabal file: with your existing approach, you either have to manually
apply follow the changes or to clobber your defaults each time and write
them up again, both tedious and rather error prone.

With that setup, your nix-shell works as always. Your nix-build should
be pointed at shell.nix however, which is a minor difference.

-- 
Mateusz K.


More information about the nix-dev mailing list