Nix expression that builds stack project using stack build --nix: Would it be a problem?

I have a Stack Haskell project. I want to package it using Nix.
I’m thinking about writing a simple default.nix that

  • has dependency to Stack
  • builds the project using stack build --nix.

At a glance it raises red flag becaues this nix expression doesn’t declare any buildtime/runtime haskell package dependencies but at the same time I don’t see why not.

Would it be a problem?

Btw, please don’t say I should use haskell.nix. Avoiding haskell.nix is the reason I’m asking this question in the first place.

This is basically what the stack builder in Nixpkgs does:

The big problem with this is that it is not pure. stack uses the internet to fetch dependencies, so you need to disable the sandbox when you’re building. (I imagine it is possible you could work around this with a FOD for the Haskell deps that stack downloads, but I’ve never seen someone attempt that.)

While some people use impure builds as a first step in moving to Nix, most people try to keep their Nix-based builds pure. In practice, you don’t see many people recommending these types of impure builds.
Most people would consider building like this a “problem”, but I guess it is up to you if you’re okay with it.


As for what I would suggest you do, I wrote up a post that explains your main choices for building Haskell projects with Nix:

If you want to build a Haskell project with Nix, using a stack.yaml as a single source of truth, and not using haskell.nix, as far as I know you’re currently out of luck.

There is an old project that did this, but I don’t think anyone is maintaining it right now:

Although, this is something that people ask for frequently, so if you wanted to take the initiative to update this project and get it working with the latest version of stack, you may very well have some appreciative users!

2 Likes
Hosted by Flying Circus.