2022-12-15
For a while now I've wanted a way to use Nix to build a Haskell package that has a stack.yaml
file. The go-to method in the Haskell community is to use haskell.nix, but haskell.nix has a few downsides1:
- Evaluation can take quite a while, and building your project without using the IOHK cache can take a very long time.
- haskell.nix is quite complicated. It can be hard to figure out problems and fix bugs.
- It is completely separate from the Haskell infrastructure in Nixpkgs.
I decided to write a Nix library called stacklock2nix
. It generates a Nixpkgs-compatible Haskell overlay from a stack.yaml
and stack.yaml.lock
file. This allows you to easily build a Haskell project with Nix (as long as you have a stack.yaml
and stack.yaml.lock
file). It allows you to use your stack.yaml
file as a single-source-of-truth for Haskell dependency versions2.
You can find usage instructions, as well as two example projects in the README.
I've decided to do a series of blog posts where I use stacklock2nix
to package various Haskell projects. Check out each one for a realistic example of using stacklock2nix
:
-
This post introduces an easy way to build a straight-forward Haskell project with
stacklock2nix
. This is good for beginners. -
This post introduces an advanced way to build a Haskell project with multiple packages. This is good for developers who need ultimate flexibility.
-
This post is similar to the post about building the PureScript compiler, but it sets up Pandoc to be statically linked. This would be a good example to follow for people that want to distribute fully statically-linked Haskell binaries.
Footnotes
haskell.nix of course has a bunch of good points as well.↩︎
As opposed to manually keeping dependency versions in sync between
stack.yaml
and your Nix code.↩︎