How to use different ghc builds with stack?

You can use the ghc-variant option or --ghc-variant flag.

If you are on Windows and use the default stack-setup-2.yaml, building with --ghc-variant integersimple should use a different GHC than if you use --ghc-variant standard.


The other answers are good, but here's a complete example so that you don't have to puzzle it together from the provided links.

Put this in your stack.yaml file:

resolver: lts-12.20

setup-info:
  ghc:
    linux64-custom-dwarf:
      8.4.4:
        url: "https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-deb9-linux-dwarf.tar.xz"
        sha256: f9cac6e402c71d7251f2e22f412fb4abd72c64f34481a1e548cd7f6ff2352a07

ghc-variant: dwarf

Here in the setup-info part I provide the path to the bindist, a checksum (optional but recommended for reproducibility), and then say that I want to use this custom ghc with ghc-variant: dwarf (it seems to turn the dwarf in there into linux64-custom-dwarf by appending the word to linux64-custom-).

If you want to share the definition of that custom ghc across projects, you can also put the setup-info part into $HOME/.stack/config.yaml.


Note for GHC hackers: If you want to hack on ghc itself and iterate quickly on your packages with frequently updated GHC, then this approach where you just override the GHC binary instead of declaring a fully built bindist is better (because you don't have to build a bindist every time you recompile).


For people who want to try a different ghc version and not an entirely different build alltogether the --compiler flag is useful https://docs.haskellstack.org/en/stable/yaml_configuration/#compiler

Also take a look at this answer https://stackoverflow.com/a/35472448/1833322 which talks about the --ghc-variant flag

And to be complete, here is the talk about the implementation of these flags:

  • https://github.com/commercialhaskell/stack/issues/530
  • https://github.com/commercialhaskell/stack/pull/816

This is useful to know since this stackoverflow question is the first page in google results.