blog / posts /

Full commit
title: Deploying Gitit (with plugins)
author: John Lenz
tags: haskell, gitit
date: September 20, 2012

As I explained in an earlier post on [BibTeX and Gitit](2012-06-26-bibtex-and-gitit.html), I would
like to run [gitit]( on my Debian stable server with a plugin to display
links to references. Rather than attempt to install all the development tools like the latest GHC on
Debian stable, I instead [use LXC](2012-09-19-cross-build-haskell-using-lxc.html) to get a Debian
environment on my development machine so that I can build executables to run on Debian stable.

There are two issues that need to be overcome to make this work.

* Gitit accesses data files using getDataFileName from Cabal, and by default when using virthualenv,
  this directory is ~/path/to/virtenv/.cabal/share.  This path will either need to be changed or
  copied to the server during deployment.
* Gitit plugins which are loaded at runtime require GHC to be installed.

Luckily, both issues can be overcome.  For the data file problem, we can pass --datadir to cabal
when building to specify the data directory.  Thus we just need pick a path which will exist on both
the development LXC container and the target machine.  I picked a path in /opt, but you can use any
path. Inside the LXC container, run

# cd /opt
# sudo mkdir cabaldata
# sudo chown `whoami` cabaldata

Now create a gitit virtual environment and install gitit (and its dependencies) with the specified
data directory.

# mkdir gitit-env; cd gitit-env
# virthualenv
# source .virthaulenv/bin/activate
# cabal install --datadir /opt/cabaldata gitit

To support plugins, rather than copy the gitit exe that was just built, we will instead compile a custom
gitit with the plugin compiled directly into the executable: here is the code.  Note this is a
slightly modified chunk of code which was taken from the [hackage gitit

~~~ {.haskell}
import Network.Gitit
import Happstack.Server.SimpleHTTP
import qualified BibtexGitit as BG

main :: IO ()
main = do
    conf <- getConfigFromFile "config"
    createStaticIfMissing conf
    createTemplateIfMissing conf
    createRepoIfMissing conf
    initializeGititState conf
    updateGititState (\s -> s { plugins = plugins s ++ [BG.plugin] })
    simpleHTTP nullConf{port = 5001} $ wiki conf

I have the above code in a file called [gitit.hs](/code/gitit.hs) if you want to download it
instead.  Note the code requires [BibtexGitit.hs](/code/BibtexGitit.hs) described
[here](2012-06-26-bibtex-and-gitit.html) to be located in the same directory.  Also, the path to the
config file is hard-coded in, you could copy more code from [the default
gitit.hs]( to support command arguments or to add
logging.  I just compile with

# ghc --make gitit.hs

Once I copy the built gitit executable along with the /opt/cabaldata directory, gitit starts and
runs perfectly.  Remember to remove the plugin from the config file, since it is now baked right
into the exe.