__NoChroot error trying to integrate stack build into NixOS configuration.nix

To get past your immediate error, you can use the Nix option --option sandbox relaxed. This turns off the sandboxing for your Stack build.

Although, most people using Haskell with Nix don’t use the generic stack builder from Nixpkgs. One of the main reasons is the requirement that you turn off sandboxing!

So what are your options for building Haskell projects with Nix? I have a small list here:

If you absolutely want to build a stack-based project with Nix, you have three main options:

  1. Pick a version of Nixpkgs that uses the same LTS version your project is based on, and then use haskellPackages.developPackage or haskellPackages.shellFor for building your project.

  2. Use haskell.nix. This has very good support for building from a stack.yaml file. The downside is that it can be quite complex.

  3. Use stacklock2nix. This is a little simpler than haskell.nix (although I’d hesitate to say that it is “beginner-oriented”).