cabal install –global considered harmful…

I had been installing Haskell packages using “cabal install –global”, as root. When the Debian Sid maintainers pushed out an update to GHC (The Glasgow Haskell Compilation system), it broke compilation of my XMonad configuration (because the DBus package was not available to the new GHC). My old xmonad configuration binary still worked, but I couldn’t make any changes to it.

I had been using the base GHC packages in Debian, but installed extra packages using the “cabal” installer. Even worse, I had been passing the –global option, since I was running “cabal install” as root. Since I had installed DBus using cabal in this way, when GHC updated to 7.6.3, DBus no longer worked.

I discovered this article describing some pitfalls of using cabal. Unfortunately none of them told me how to get out of this predicament. Thanks to typoclass and merijn in #haskel@irc.freenode, I was able to restore functionality (this time without using cabal to install the DBus modules). Here’s how I did it:

  1. I moved the GHC global directories to a backup location. To determine these I used the command:
    ghc-pkg list

    I did have to recreate the /var/lib/ghc/package.conf.d directory, so apt would not complain that it didn’t exist (and thus fail to remove the ghc package).

  2. I removed ghc using the command
    aptitude purge ghc libghc-? cabal-install xmonad ghc-doc ghc-haddock

    This is not actually the command I ran, but after repeating these instructions on my primary home workstation and laptop, I wanted to put everything into one command to make it easier for next time.

  3. Installed the DBus modules through apt:
    aptitude install libghc-xmonad{,-contrib}-dev libghc-dbus-dev xmonad

    This appears to have pulled in most of the packages I needed.

  4. Recompiled my XMonad configuration with the command:
    xmonad --recompile

    No more compilation errors!

From now on I will try to find a Debian package which provides the Haskell modules I need, rather than resorting to using cabal (note that cabal-installer is explicitly removed here). Granted, my Haskell installation will not be current with upstream, but hopefully a GHC update via apt won’t break the compilation of my xmonad.hs file again. If I do need to use cabal to install Haskell modules, I’ll use it as my normal user, not root. That way my cabal configuration and local user ghc files can be wiped out more easily.