Search code examples
haskellcabalyesod

How can I run a scaffolded Yesod website in a cabal sandbox?


Let's say I have a cabal sandbox at folder root and I've installed the yesod packages in it. Then, I do:

root> yesod init

I go through the prompts and end up with a folder project inside root.

yesod devel doesn't appear to support passing sandbox arguments to it, so any packages I install in the sandbox are not visible to the scaffolded Yesod site (and I don't want to install everything in the global space, because that's impossible to manage and replicate).

I've tried the suggestion here, but that gives me these errors:

root> runhaskell -no-user-package-db -package-db=.cabal-sandbox\x86_64-windows-ghc-7.8.4-packages.conf.d project/app/main.hs

project\app\main.hs:2:8:
  Could not find module `Application'
  Use -v to see a list of the files searched for.

Running it inside root/project:

root/project> runhaskell -no-user-package-db -package-db=../.cabal-sandbox\x86_64-windows-ghc-7.8.4-packages.conf.d app/main.hs

Foundation.hs:6:8:
  Could not find module `Text.Jasmine'
  Use -v to see a list of the files searched for.

Settings.hs:8:8:
  Could not find module `ClassyPrelude.Yesod'
  Use -v to see a list of the files searched for.

Settings.hs:14:8:
  Could not find module `Database.Persist.Sqlite'
  Perhaps you meant
    Database.Persist.Sql (from persistent-2.1.2)
    Database.Persist.Sql.Util (from persistent-2.1.2)
    Database.Persist.Class (from persistent-2.1.2)
  Use -v to see a list of the files searched for.

Settings\StaticFiles.hs:4:8:
  Could not find module `Yesod.Static'
  Use -v to see a list of the files searched for.

Does anyone know of a flag I can set or something?


Solution

  • This should work:

    just init a sandbox where you scaffolded your site

    cabal sandbox init --sandbox=[path to yesod-sandbox]
    

    or alternatively just init a new sandbox

    cabal sandbox init 
    cabal install --dependencies-only
    

    script

    there is even a script written by KrdLab that automates this using stackage:

    wget http://www.stackage.org/lts/cabal.config
    cabal update
    cabal sandbox init
    cabal install alex happy yesod-bin
    export PATH=./.cabal-sandbox/bin:$PATH
    yesod init --bare
    cabal install -j --enable-tests --max-backjumps=-1 --reorder-goals
    yesod devel