[Nix-dev] Haskell Infrastructure - Nix-Shell with Hoogle from cabal2nix

Andreas Herrmann andreash87 at gmx.ch
Tue Feb 16 10:57:00 CET 2016


Hi Peter,

Thanks for your response.

On Monday 15 February 2016 19:17:52 Peter Simons wrote:
>  > In order to create a development environment, where I have
>  > `cabal-install` available as well, I can write the following Nix
>  > file: [...].
> 
> why don't you just put inherently compiler-agnostic tools like
> cabal-install, stack, alex, happy, etc. into your user's profile or
> system profile? Then all your nix-shells will have access to them.

I'm not using Nixos, but Nix in single user mode on a host system. I use Nix for a bunch of different things. To avoid any collisions I've developed a habit of keeping as many things as possible in separate nix-shells rather than in my user profile. In the case of cabal it probably wouldn't hurt to put it in my user profile. Here it was meant as an example of how to add things to the development environment.

On Sunday 14 February 2016 14:48:54 Andreas Herrmann wrote:
> shell.nix
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> { nixpkgs ? import <nixpkgs> { }, compiler ? "default" }:
> let
> 
>   inherit (nixpkgs) pkgs;
>   haskellPackages = if compiler == "default"
>   
>                         then pkgs.haskellPackages
>                         else pkgs.haskell.packages.${compiler};
>   
>   inherit (pkgs.haskell.lib) addBuildTools;
>   pkg = import ./pkg.nix { inherit nixpkgs compiler; };
> 
> in
> (addBuildTools pkg (with haskellPackages; [ cabal-install ])).env
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
> # My Question
> 
> How could I instead get a development environment with a Hoogle package
> database of all the dependencies. I know that I could manually create the
> following Nix file and use it with `nix-shell ./shell-manual.nix`.
> 
> shell-manual.nix
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> { nixpkgs ? import <nixpkgs> { }, compiler ? "default" }:
> let
> 
>   inherit (nixpkgs) pkgs;
>   haskellPackages = if compiler == "default"
>   
>                         then pkgs.haskellPackages
>                         else pkgs.haskell.packages.${compiler};
>   
>   ghc = haskellPackages.ghcWithHoogle (pkgs: with pkgs; [
>   
>           base bytestring cabal-install
>         
>         ]);
> 
> in
> pkgs.stdenv.mkDerivation {
> 
>   name = "dummy";
>   buildInputs = [ ghc ];
>   shellHook = "eval $(egrep ^export ${ghc}/bin/ghc)";
> 
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> However, then I would have to manually maintain an extra dependency list. Is
> there any way of transforming the Nix-Shell environment produced by
> `pkg.env`
> in `shell.nix` above into one that adds a Hoogle database of all the
> included
> packages?

In any case, the question about a Hoogle database remains. I find it very useful in situations where I don't have a reliable Internet connection at hand. (train/plane/etc.)

Best, Andreas


More information about the nix-dev mailing list