Building Haskell project with specific Stackage snapshot using Haskell.nix

I am trying to build a small Haskell project using Haskell.nix. I need to check if it builds in a range of stackage snapshots. I am using the example code given at Haskell.nix .
I am not able to understand how to give a particular stackage snapshot packages as input here

            final.haskell-nix.project' {
              src = ./.;
              compiler-nix-name = "ghc8104";
              # This is used by `nix develop .` to open a shell for use with
              # `cabal`, `hlint` and `haskell-language-server`
     = {
                cabal = {};
                hlint = {};
                haskell-language-server = {};
              # Non-Haskell shell tools go here
              shell.buildInputs = with pkgs; [
              # This adds `js-unknown-ghcjs-cabal` to the shell.
              shell.crossPlatform = p: [p.ghcjs];

You should put it in stack.yaml and use stackProject. This is the quickest way, really.

1 Like

I think @greydot is correct here. The easiest thing will probably be to have multiple stack.yaml files, and call haskell-nix.project or haskell-nix.project' or haskell-nix.stackProject with each of them.

Here’s an example of a Haskell project with multiple stack.yaml files: GitHub - cdepillabout/password: datatypes and functions for easily working with passwords in Haskell. You’ll have to turn your above code into a function and accept an argument taking which stack.yaml file to use.

Although, it is probably possible to do this directly with haskell.nix as well. I’d suggest looking into the haskell.nix code for how to get started with this.

Here’s a couple links that might be helpful:

I’m somewhat surprised there is no option in modules/stack-project.nix for setting the resolver (which would let you easily build with a different Stackage snapshot).

You might want to ask on the haskell.nix issue tracker, or the haskell.nix IRC channel if you still want to try to do this.

1 Like