Skip to content

Instantly share code, notes, and snippets.

@patrl
Last active January 9, 2020 21:53
Show Gist options
  • Save patrl/9b73c45d1c948057e4111756f708a7f2 to your computer and use it in GitHub Desktop.
Save patrl/9b73c45d1c948057e4111756f708a7f2 to your computer and use it in GitHub Desktop.
Setting up a jupyter notebook with iHaskell on windows

The existence of WSL 2, the nix package manager, and tweag.io's jupyterWith project make it (relatively) easy to set up a working jupyter notebook with the iHaskell kernel in windows 10.

Step 1: Install WSL 2

  • If you don't already have it up and running, start by making you sure you have WSL 2 installed and activated, by following the instructions here. At the time of writing, you need to join the windows insiders program (slow ring is sufficient).
  • I use Ubuntu from the windows store with WSL 2, but the following instructions should be compatible with any distribution.

Step 2: Install the nix package manager

  • Open a ubuntu terminal and install the nix package manager by running the following command:
curl https://nixos.org/nix/install | sh

Step 3: Install cachix and enable caching (optional)

  • Now install the nix binary cache manager cachix using nix, with the following command. This is strictly speaking optional, but highly recommended as it will significantly speed up subsequent steps.
nix-env -iA cachix -f https://cachix.org/api/v1/install
  • Enable the jupyterWith cache by running the following command:
cachix use jupyterwith

Final step: create and run an example project

  • Create and cd into a new directory. Let's call it ihaskell-test.
  • Create an empty directory within ihaskell-test called jupyterlab.
  • Create a new file in ihaskell-test called shell.nix, with the following contents:
let
  jupyter = import (builtins.fetchGit {
    url = https://github.com/tweag/jupyterWith;
    rev = "";
  }) { config = {allowBroken = true;};};

  iHaskell = jupyter.kernels.iHaskellWith {
    name = "haskell";
    packages = p: with p; [ hvega formatting ];
  };

  jupyterEnvironment =
    jupyter.jupyterlabWith {
      kernels = [ iHaskell ];
      directory = ./jupyterlab;
    };
in
  jupyterEnvironment.env
  • Inside of ihaskell-test run nix-shell. It will take a while for everything to build.
  • Once the process has finished, run generate-directory jupyterlab-ihaskell This is necessary for syntax highlighting to work.
  • Now, exit the nix shell environment via Ctrl-D.
  • Finally, run the following command to start the notebook:
nix-shell --command "jupyter lab"
  • You can navigate to the provided url in a windows browser to access the notebook interface.

Happy hacking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment