Skip to content
A template for developing with Haskell using Nix
Nix Haskell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode HIE works Jan 10, 2020
nix
packages/hello-world
.gitignore
README.md
shell.nix HIE works Jan 10, 2020

README.md

Haskell Nix dev template

A template for completely reproducile build and development in Haskell using Nix.

How to use

Dependencies

  1. Install Nix

Please find the documentation here: https://nixos.org/nix/manual/#chap-installation

TL;DR

bash <(curl https://nixos.org/nix/install)
  1. Install VS Code and some plugins:
    • Nix Environment Selector
    • Haskell Syntax Highlighting
    • Either ghcide for ghcide (default) or Haskell Language Server for HIE (slower but has a bit more tools)

Recommanded steps for faster use

Nix will compile everything that is not in the cache, especially HIE, GHCIDE, etc. In order to build the environment faster, please use Cachix.

  1. Install Cachix
nix-env -iA cachix -f https://cachix.org/api/v1/install
  1. Add caches for this project
cachix use all-hies
cachix use hercules-ci

Get started

  1. Clone this repository
git clone https://github.com/GuillaumeDesforges/haskell-nix-dev-template.git
cd haskell-nix-dev-template
  1. Build the environment for the first time
    • Wait for the build to complete. It can be very long but don't worry, it will work almost instantly next time.
nix-shell --run "echo Sucessfully built the environment"
  1. Start VS Code
code .
  1. Use Nix Environment Selector (bottom left of the VS Code window, in the toolbar) to select shell.nix as the environment.

    • Reload the VS Code window when asked (a notification will pop up at the bottom right of the window).
  2. You can now create projects (Cabal packages) in the ./packages directory.

Repeat from step (2) when you add, remove or modify a .cabal file.

Configuration

Some parameters can be configured by editing the file ./nix/confgi.nix.

For now you can:

  • Change the GHC version to use
    • Warning: check that this version is supported by nixpkgs and your IDE
  • Select the IDE used
    • For now either ghcide (default) or HIE

Motivations

I found setting up a Haskell project way more complicated than nearly any modern language. I decided to make once and for all a way for beginners such as myself to start playing with Haskell quickly without spending so much time thinking about the IDE.

The philosophy

  1. The development can be started after only a few commands in CLI.
  2. Use Nix to handle packages (Haskell compiler, development tools).
  3. Use Cabal for the Haskell package definition.
  4. Use VS Code to write code.

Please note that this is not educational content.

It is not a reference, nor is it readable for a beginner in Nix. It just gets the job done enough in order to spend less time on setting up an environment as a beginner.

Credits

Huge credits to https://github.com/fghibellini/nix-haskell-monorepo/. You must go there if you want to go any futher into Haskell & Nix from this repo.

You can’t perform that action at this time.