Hakyll cabal-dev procedure

posted: 2013-Feb-19

For a sane system, it’s great to build Haskell libraries and things with cabal as --user instead of --global. I’m also increasingly using the popular cabal-dev tool to isolate build dependencies even more.

hakyll represents a challenge to working this way, but I was pretty sure it could be rigged to work with some symlinks.

The overall goal for me was this:

To start with, the only dependency aside from the GHC and cabal-install is cabal-dev. There is the official source for it at Hackage, BUT because of some GHC 7.6.x build trouble (that I’m certain will be fixed soon), I ended up using cabal-dev from github. This version has some very recent patches.

Now, here’s what I did step by step to install hakyll and its deps:

Install hakyll using cabal-dev

We’re installing hakyll one-time, with the idea of sharing it across multiple weblogs if desired. So let’s make a directory to organize all this weblog work:

$ mkdir weblog

And now install cabal-dev here

$ cd weblog
$ cabal-dev install hakyll

This will take a while, hakyll’s dependencies are big. Of course it may be good to upgrade this now and again as new versions of hakyll are released.

Making a new weblog site

You’ll do this once per weblog, this is a weblog initial setup. Let’s use hakyll-init to generate the new weblog’s base set of files:

$ cd weblog  # if not already there
$ ./cabal-dev/bin/hakyll-init my-site

In order to use cabal-dev to build the weblog’s own software we need a .cabal file for it:

$ cd my-site
$ cabal init

We don’t need to go out of our way to fill this info out thoroughly, but a few things are required or handy to have:

Now edit the site.cabal file

Finally, let’s link the cabal-dev directory one level up to here:

$ ln -s ../cabal-dev

Once this is done, we can use cabal-dev from this directory to build site.hs into the binary for this weblog. Build it the first time:

$ cabal-dev configure
$ cabal-dev build

Use cabal-dev like this to rebuild whenever changes are made to the site.hs or other code.

Make a convenience link to the binary. This is the tool that will build your static site pages.

$ ln -s dist/build/site/site

Making posts on your weblog

Edit files in posts, or templates or whatever and then build in the normal hakyll way:

$ ./site build

From here, I refer you back to the hakyll documentation for maintaining and working with a hakyll site.