Haskell Nix dev template
A template for completely reproducile build and development in Haskell using Nix.
How to use
- Install Nix
Please find the documentation here: https://nixos.org/nix/manual/#chap-installation
bash <(curl https://nixos.org/nix/install)
- Install VS Code and some plugins:
Nix Environment Selector
Haskell Syntax Highlighting
ghcidefor ghcide (default) or
Haskell Language Serverfor 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.
- Install Cachix
nix-env -iA cachix -f https://cachix.org/api/v1/install
- Add caches for this project
cachix use all-hies cachix use hercules-ci
- Clone this repository
git clone https://github.com/GuillaumeDesforges/haskell-nix-dev-template.git cd haskell-nix-dev-template
- 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"
- Start VS Code
Nix Environment Selector(bottom left of the VS Code window, in the toolbar) to select
shell.nixas the environment.
- Reload the VS Code window when asked (a notification will pop up at the bottom right of the window).
You can now create projects (Cabal packages) in the
Repeat from step (2) when you add, remove or modify a
Some parameters can be configured by editing the file
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
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 development can be started after only a few commands in CLI.
- Use Nix to handle packages (Haskell compiler, development tools).
- Use Cabal for the Haskell package definition.
- 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.
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.