Shell.nix for "Parallel and Concurrent Programming in Haskell" by Simon Marlow

Hello,

I’ve made this shell.nix that allows for me to reliably build the packages and follow along with the book using cabal.

# shell.nix
{ nixpkgs ? import (builtins.fetchTarball {
                      url = "https://github.com/NixOS/nixpkgs/archive/5c79b3dda06744a55869cae2cba6873fbbd64394.tar.gz"; 
# Pins to a version of nixpkgs where ghc 8.8.4 was the main ghc (I think)
# gotten from https://lazamar.co.uk/nix-versions/?package=ghc&version=8.8.4&fullName=ghc-8.8.4&keyName=ghc&revision=5c79b3dda06744a55869cae2cba6873fbbd64394&channel=nixpkgs-unstable#instructions
                      }) {}, 
                    }:


let 
  hpkgs = nixpkgs.haskell.packages."ghc884";

in 
  hpkgs.shellFor {
    name = "parconc-examples";
    packages = _: [];
    buildInputs = with hpkgs; [ 
      cabal-install
      haskell-language-server
      nixpkgs.pkg-config # Needed to build some packages
      nixpkgs.zlib # Needed to build some packages
      implicit-hie
  ];
}
  1. Enter the environment with nix-shell.
  2. Update cabal with cabal update.
  3. Build the executable(s) with cabal build [package]
  4. Run the executable with cabal run. So for example:
$ ghc -O2 rpar.hs -threaded
$ ./rpar 1 + RTS -N2

becomes

$ cabal build rpar
$ cabal run rpar 1 -- +RTS -N2

EDIT: Got HLS working.

Added implicit-hie to buildInputs.

OPTIONAL: To work with HLS, in the nix-shell, run gen-hie > hie.yaml

3 Likes