Haskell Nix template

I’ve been developing Haskell projects using a combination of the following which I really enjoy using,

  • Nix (for reproducible dev environment)
  • Nix Flakes (improved workflow in Nix, especially for pinning)
  • VSCode + haskell-language-server (for IDE support)
  • ormolu for autoformatting
  • Relude as prelude
  • ghcid for quick reloading

So I decided to create a Git template for re-use in future Haskell projects, and thought it may be of interest to others.

The README is self-sufficient in that you should be able to get started on all three platforms (For Windows, WSL2 + the Remote - WSL VSCode extension is required).

18 Likes

This template now works on M1 Mac as well.

3 Likes

The bulk of Nix in this template have recently been moved to a flake-parts module of its own: https://github.com/srid/haskell-flake

2 Likes

A small template that demonstrates how to nixify a multi-package Cabal project using nothing but[^1] nixpkgs

Esssentially, pkgs.haskellPackages.extend and shellFor is all you need, in addition to whatever functions provided by pkgs.haskell.lib as appropriate (example).

[^1]: To be fair, the flake.nix uses flake-parts but only for convenience. It is not strictly needed.

4 Likes

haskell-flake now supports multi-package Haskell projects!

See haskell-multi-nix/flake.nix at master · srid/haskell-multi-nix · GitHub for a simple example.

1 Like

haskell-flake has a documentation site: https://haskell.flake.page/

I plan to write a series of guides on using Nix for Haskell projects over time.

2 Likes

Hello, I’m trying to apply haskell-flake to an existing project that uses a FFI and it fails to build. I used nix flake init -t github:srid/haskell-flake, I edited the flake.nix to set the default package name and I get an error saying that there’s an undefined symbol from the FFI when trying to build.

I’m sure I’m missing some configuration parameter to enable this but I haven’t found any information about what it could be. Any ideas?