Source

blog / posts / 2012-09-20-deploying-gitit.page

---
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](http://gitit.net/) 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
documentation](http://hackage.haskell.org/packages/archive/gitit/latest/doc/html/Network-Gitit.html).

~~~ {.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](https://github.com/jgm/gitit/blob/master/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.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.