When attempting to set up a web project using Yesod and Fay I ran into some really basic problems just building a project scaffolded with the pf template.

I’m posting a quick note about this in case anyone gets bitten by it too.

So, to create the project I did the following commands as per docs:

➜  yesod init
# enter project name and select the 'pf' option for postgres & fay 
➜  cd myproject; and cabal install --max-backjumps=-1 --reorder-goals; and yesod devel 

If you have all dependencies such as the postgresql client dev libraries installed, the build will likely fail with this error:

    Exception when trying to run compile-time code:
      ghc-pkg describe error:
ghc-pkg: cannot find package fay-base

    Code: fayFile' (Language.Haskell.TH.Syntax.ConE 'StaticR) "Home"
    In the splice: $(fayFile' (ConE 'StaticR) "Home")

Now, in various places such as the actual official docs or this thread the solution for cabal versions up 1.20 is to set and export the HASKELL_PACKAGE_SANDBOX environment variable. But even after setting it in fish it didn’t work:

➜  set HASKELL_PACKAGE_SANDBOX .cabal-sandbox/x86_64-linux-ghc-7.8.3-packages.conf.d/
# doesn't work, so tried 
➜  set -g HASKELL_PACKAGE_SANDBOX .cabal-sandbox/x86_64-linux-ghc-7.8.3-packages.conf.d/
# ...thinking that -g (global) is the equivalent of exporting a variable in bash

After banging my head against this problem for a while (also trying to integrate other fay packages such as fay-jquery, fay-text or fay-dom) I decided I’m going to do one thing I should have done first: RTFM :)

The solution is to use the -x flag:

➜  set -x HASKELL_PACKAGE_SANDBOX .cabal-sandbox/x86_64-linux-ghc-7.8.3-packages.conf.d/

After that, building works fine :)

comments powered by Disqus