[Nix-dev] How to set a specific GHC version?

Hilco Wijbenga hilco.wijbenga at gmail.com
Thu Aug 6 07:59:31 CEST 2015


Hi all,

This must be very simple but I have been unable to figure it out.
Somewhere on the great, wide Internet I found how to create a
default.nix and a shell.nix to set up a basic Haskell development
environment (see [1] and [2]).

That works fine but gets me whatever the default GHC currently is. I
would like to set explicitly which version I'm using. Once I've got
that covered, how do I set explicit versions for the packages I'm
including as well? Just adding a version to the package name doesn't
work.

Finally, (specifically for the first question) how could I have
figured that out for my self? Could someone teach me to fish? :-) I
did read up on Nix expressions and looked at the nixpkgs.git but I was
unable to figure it out.

(I have installed Nix on my Gentoo box. I've removed all Gentoo
Haskell related packages and I'm trying to set up a Haskell
development environment using Nix only.)

Cheers,
Hilco

[1] default.nix:
{ stdenv, haskellngPackages }:

let
  env = haskellngPackages.ghcWithPackages (p: with p; [
    cabal-install
    cabal2nix
    classy-prelude
  ]);
in
  stdenv.mkDerivation {
    name        = "project-name";
    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 )
    '';
  }

[2] shell.nix:
{ pkgs ? (import <nixpkgs> {}) }:

(import ./default.nix) {
    stdenv            = pkgs.stdenv;
    haskellngPackages = pkgs.haskellngPackages;
  }


More information about the nix-dev mailing list