[Nix-dev] A Journey into the Haskell NG infrastructure: Part I

Peter Simons simons at cryp.to
Fri Jan 9 19:11:46 CET 2015


Hi Thomas,

 > I changed my sandbox code to look like the following. Is that how it's
 > intended to be used?

yes, exactly. That's a very nice example. You can put that definition into a
file, say shell.nix, and run

  $ nix-shell --pure shell.nix

to obtain an interactive environment that contains the compiler defined above.

If you want to go all out, you can also add a "shellHook" attribute to make
nix-shell define the magic environment variables that tell the 'ghc-paths'
package how to use your environment. For example:

 | { pkgs ? (import <nixpkgs> {}).pkgs }:
 |
 | let
 |
 |   env = pkgs.haskellngPackages.ghcWithPackages (p: with p; [
 |     text mtl transformers warp cabal-install
 |   ]);
 |
 | in
 |
 | pkgs.stdenv.mkDerivation {
 |   name = "hello-world-wide-web";
 |   buildInputs = [ env ];
 |   shellHook = ''
 |     export NIX_GHC="${env}/bin/ghc"
 |     export NIX_GHCPKG="${env}/bin/ghc-pkg"
 |     export NIX_GHC_DOCDIR="${env}/share/doc/ghc/html"
 |     export NIX_GHC_LIBDIR=$( $NIX_GHC --print-libdir )
 |   '';
 | }

Best regards,
Peter



More information about the nix-dev mailing list