Skip to content

stack.yaml

When I introduced you to Stack as one of the tools we need to build Haskell code, I emphasized that one of the advantages that Stack offers is that it creates reproducible builds by ensuring we always build our package with the same compiler and package versions even if newer versions of the compiler and packages are available. If you open stack.yaml, you'll see a whole list of configuration options in the file. The one I want you to focus on is

resolver:
  url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/15.yaml

This specifies the snapshot of the compiler and packages to be used to build the project. A shorter way to specify the same snapshot is using

resolver: lts-20.15

This stands for "Long Term Support version 20.15". Each snapshot contains a combination of compiler version and Hackage packages that are known to work together correctly. When creating a new project using stack new, the resolver line in stack.yaml will always be filled in using the most recent snapshot available on Stackage.

If we know that our project builds only using a specific version of GHC or of a package, then we can search Stackage for a snapshot that includes this compiler or package version and change the resolver entry to the snapshot we need to use.

In fact, this is the situation we find ourselves in when compiling our code on timberlea. Remember, we need to avoid downloading our own copy of GHC. We changed the resolver line for the "global project", the one used when we're not inside a project directory created by stack new, to

resolver: lts-18.28

to ensure we build our code using GHC 8.10.7, which is the one installed on timberlea. Thus,

Warning

For every project we build on Timberlea, we need to change the resolver and system-ghc lines in stack.yaml to

resolver: lts-18.28
system-ghc: true

The system-ghc line instructs Stack to use the GHC compiler installed in a system-wide location on timberlea, instead of downloading our own copy.

Other configuration options in this file include specific compiler settings to be used to compile our project and instructions on how to find packages that our project depends on and which are not available from Hackage. We won't discuss those here.

Apart from setting resolver and system-ghc to the correct values if you are compiling your code on timberlea, you should leave stack.yaml alone for the projects you implement in this course.