Andrey Prokopenko's Blog

Implementing stack support in Fay


This year started fenomenally: I became the fay compiler maintainer.

I have a small side project built with ghc, yesod, stack and fay. And yesod-fay. One day after migration to GHC 8 I corrupted .stack-work and decided to recreate it. After that errors appeared from fay side.

Could not find module

or even

ghc-pkg: Could not find package

Or something like that.


In fay wiki stated that it is necessary to set up HASKELL_PACKAGE_SANDBOX variable. The point is that stack usually takes care of it and rewrite your value with a new one.

stack path

Command above will give you a clue. It happened because there are several package databases.

  • Global one which came with your system GHC and located somewhere in ~/.cabal.
  • Another one which came with stack snapshot and located as you may understand somewhere in ~/.stack.
  • And the local one (also handled by stack somewhere in ~/path/to/your/project/.stack-work.

Before GHC 8 the main idea of how to avoid cabal-hell was cabal sandbox. And it was reflected in fay wiki. When stack appeared, it takes management of local dependencies and even package database by itself.

Thus, during fay compilation stack decided to switch from local package to its global. And lookup for dependent package was failed.

Since fay does not have typechecker, it relies on GHC and uses ghc-paths. Under the hood there was usage of ghc-pkg and stack package db. There was a mess.

I decided to implement checks for ghc-pkg usage on both sides: fay and yesod-fay. Manual compilation should work in stack project. Compilation through the Fay API should work as well.


Finally I was able to fix two packages. And become maintainter of them and move on.


With GHC 8.4 and further there is another approach to build packages: cabal new-build or cabal v2-build. And it seems that ghc-pkg should be adopted again.

Posted on 2019-04-30 by agr . Powered by Hakyll. Inspired by Yann Esposito.