Haskell package guidelines

From ArchWiki
Revision as of 10:23, 14 June 2008 by Gwern (talk | contribs) (Libraries: sp)
Jump to: navigation, search

Haskell on Arch Linux


  • all hackage packages into AUR or community.
  • automatic conversion of new cabal packages to AUR packages
  • make Arch Linux the most up to date Haskell platform around


#arch-haskell on freenode.


We're working on a tool to automate PKGBUILD generation. Latest version of cabal2arch is here,

Development version:


  • cabal install cabal2arch

This will automate the entire process, allowing us to import the 500+ libraries on hackage, and keep them up to date.

Creating new packages with cabal2arch

This example illustrates how to create a new package with cabal2arch. We'll make a new package for the delimited continuations library, CC-delcont:

First, find the hackage page for CC-delcont, then identify the link to the .cabal file. Use this link as an argument to cabal2arch:

$ cd /tmp
$ cabal2arch http://hackage.haskell.org/packages/archive/CC-delcont/0.2/CC-delcont.cabal
Using /tmp/tmp.Ig0H8jCOyO/CC-delcont.cabal
Fetching http://hackage.haskell.org/packages/archive/CC-delcont/0.2/CC-delcont-0.2.tar.gz
Created /tmp/haskell-cc-delcont.tar.gz

Checking what was created:

$ ls
haskell-cc-delcont  haskell-cc-delcont.tar.gz

You can now inspect the PKGBUILD and install script for the library:

   # Contributor: Don Stewart <dons@galois.com>
   # Package generated by cabal2arch
   pkgdesc="Delimited continuations and dynamically scoped variables"
   arch=('i686' 'x86_64')
   build() {
       cd $startdir/src/CC-delcont-0.2
       runhaskell Setup configure --prefix=/usr || return 1
       runhaskell Setup build                   || return 1
       runhaskell Setup register   --gen-script || return 1
       runhaskell Setup unregister --gen-script || return 1
       install -D -m744 register.sh   $startdir/pkg/usr/share/haskell/$pkgname/register.sh
       install    -m744 unregister.sh $startdir/pkg/usr/share/haskell/$pkgname/unregister.sh
       runhaskell Setup copy --destdir=$startdir/pkg || return 1
       install -D -m644 LICENSE $startdir/pkg/usr/share/licenses/$pkgname/LICENSE || return 1

It follows the conventions for Haskell packages:

  • libraries are prefixed with "haskell-"
  • core libraries are not included as explicit dependencies, since ghc provides them
  • since haskell libraries are statically linked, the package only has makedepends requirements
  • it uses cabal to generate a post-install register/unregister script, with a standard name

All Haskell libraries should follow these naming conventions, and using the cabal2arch tool will ensure this is the case.

Inspect the bundle, and confirm you can build and install it:

   $ makepkg -s
   $ makepkg -i

And we're ready to go. Now your .tar.gz is ready to upload to AUR.


In general, each .cabal file should map to one PKGBUILD. The following conventions hold:

  • libraries have their cabal names prefixed with "haskell-"
  • all haskell dependencies are statically linked, so can go in the makedepends field.
  • all libraries have a dependency on 'ghc'
  • libraries don't need to have explicit dependencies on core Haskell packages -- these come in the 'ghc' package. (e.g. array, base, containers, random, process etc).
  • we want to resolve dependencies with a fixed constraint to base>=3.0
  • be careful about dependencies on the libraries provided by the basic 'ghc' package, which include:
ALUT-        cgi-3001.1.5.1       network-       regex-base-
Cabal-       containers-   old-locale-    regex-compat-
GLUT-        directory-    old-time-      regex-posix-
HUnit-       fgl-          packedstring-  stm-
OpenAL-      filepath-     parallel-      template-haskell-
OpenGL-      haskell-src-  parsec-        time-
QuickCheck-  haskell98-    pretty-        unix-
array-       hpc-          process-       xhtml-3000.0.2.1
base-        html-         random-
bytestring-  mtl-          readline-

These libraries don't need explicit dependencies to be set.

Registering Haskell libraries is done via a register hook:

build() {
   cd $startdir/src/cabal2arch-0.1
   runhaskell Setup configure --prefix=/usr || return 1
   runhaskell Setup build                   || return 1
   -- generate register scripts
   runhaskell Setup register   --gen-script || return 1
   runhaskell Setup unregister --gen-script || return 1
   install -D -m744 register.sh    $startdir/pkg/usr/share/haskell/$pkgname/register.sh
   install    -m744 unregister.sh $startdir/pkg/usr/share/haskell/$pkgname/unregister.sh
   runhaskell Setup copy --destdir=$startdir/pkg || return 1
   -- usual Haskell BSD3 license isnt' official
   install -D -m644 LICENSE $startdir/pkg/usr/share/licenses/$pkgname/LICENSE || return 1

  • Examples:
haskell-zlib, haskell-mersenne-random


  • Have their normal name. Examples:
hmp3, xmonad, ghc, cabal-install

Building all of Hackage

The following simple script, with cabal-install and cabal2arch installed, will do a simple run over all the Haskell packages on haskell.org, creating arch packages for them:

   cabal update
   tmpdir=`mktemp -d`
   finaldir=`mktemp -d`
   cd $tmpdir
   tar xzf $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz
   for dir in * ; do 
        if [ ! -d $dir ] ; then
        cd $dir
        lib=`ls --color=never -1 | tail -1`
        echo "************** Building package for $dir-$lib"
        cd $lib
        cabal2arch *.cabal > $dir.log 2>&1
        cd `find . -type d -a ! -name '.'`
        if makepkg -sm > ../$dir.log 2>&1 ; then
            echo "OK: " $dir-$lib
            cp *.pkg.tar.gz $finaldir/
            sudo pacman -A *.pkg.tar.gz
            rm *.pkg.tar.gz
            rm -rf pkg src *.tar.gz
            cd ..
            cp -R `find . -type d -a ! -name '.'` $finaldir/
            cp *.tar.gz $finaldir/
            echo "Failed"
        cd $tmpdir
   echo `ls $finaldir/*pkg* | wc -l` "build packages in $finaldir"
   echo "Now: scp -r $finaldir/* code.haskell.org:/srv/code/arch/$MACHTYPE/"

Using cabal-install we can get a topological sort of the installable graph of modules. You can see such an install plan here.

The Haskell Overlay

A suite of binary packages and PKGBULIDs of Haskell libraries is hosted on code.haskell.org by the Arch Haskell team:


These are automatically generated via cabal2arch.