Building Debian packages of (cabalised) Haskell packages

I’ve just spent the last hour or so ironing out the details required to automate the building of cabalised Haskell packages for Debian. At the same time I also built Debian packages for 5 Haskell packages (test-framework and its dependencies).

These are the basic steps I’ve followed:

  1. Extract the tar-ball in the working directory.

  2. Rename the directory to match the form haskell-X-0.1.

  3. Re-tar the directory into an archive named haskell-X_0.1.orig.tar.gz.

  4. Change into the package directory.

  5. Run Cabal’s configure command followed by register --gen-pkg-conf=pkg.conf.

  6. Modify the generated file and turn it into a .ini-style file:

     echo '[conf]' > pkg.conf.tmp; cat pkg.conf >> pkg.conf.tmp; mv pkg.conf.tmp pkg.conf
  7. Use Python to extract the dependencies:

     python << EOF
     from ConfigParser import ConfigParser
     cfg = ConfigParser()'pkg.conf')
     deps = cfg.get('conf', 'depends').split()
     for d in map(lambda s: s.rsplit('-', 1)[0].lower(), deps):
         print d
  8. Clean up by rm pkg.conf and running Cabal’s clean command.

  9. Create the debian directory.

  10. Create debian/compat: echo 5 > debian/compat

  11. Create debian/changelog, it should be something like:

     haskell-X (0.1-1) unstable; urgency=low
       * Automatic build.
      -- Magnus Therning <>  Mon, 19 Jan 2009 22:35:00 +0000
  12. Create debian/control. This is by far the most time consuming part to do manually. It’s also a bit long so I’ll leave it out of this post. Take a look in my APT repo if you are interested in the details.

  13. Copy into debian/. At some point it will be included in some Debian package (bug #462482) but for now it can be found here.

  14. Create debian/rules with

     #!/usr/bin/make -f
     include $(CURDIR)/debian/

    and make it executable, chmod +x debian/rules.

  15. Done. Run debuild.

My intention is to at some point encode these steps in a tool so that I can spew out Debian packages for all interesting packages on HackageDB at the press of a button. Of course that tool will be written in Haskell, and it sure won’t rely on Python for any part of the process ;-)

Readers who are familiar with the rules for Debian packages will notice that this won’t create well-formed packages. I’m not particularly interested in getting these packages into Debian proper, I see the package generated this way living in an unofficial repo. So there is no need to make sure they are acceptable for inclusion in the distribution itself. The resulting packages might offer a good starting point for someone who feels that a package deserves to become official. I also suspect that a tool that generates fully compliant packages, and is able to deal with keeping them up-to-date, is too big a task for me. I’m also not sure it really is worth it, better to keep things as simple as possible in order to deal with the amazing rate of new releases on Hackage.

Mikhail Glushenkov

Looks like we really need a cabal2deb tool.

Clifford Beshers

Magnus, we have a tool called cabal-debian that does a lot of this automatically. It is incomplete and imperfect, but it’s written in Haskell ;-). See There is also a much larger tool called the autobuilder that actually builds full repositories:

Clifford Beshers SeeReason Partners, LLC

Jeremy Shaw

You may be interested in cabal-debian and the autobuilder:

Those are the tools used to maintain the repos here:

cabal-debian is a simple tool for debianizing cabal packages. Go into the top-level directory of a cabalized package and run cabal-debian --debianize.

The autobuilder is a bit more complex. It is a complete system for automatically building debian packages. It can get the package source via http, darcs, hg, svn, tla, and more. It automatically tracks build dependency and source changes to rebuild packages as needed, and installing the packages in an apt-gettable debian repository. There is an example config directory Example, which is the actual config file we use to build our repository.

The ‘missing’ pieces are:

  • cabal-debian does not automatically fetch packages from hackage
  • the process of updating the debianization when a new upstream release is made is not fully automated
  • adding new packages to the autobuilder config is currently done by hand

These features would be nice to have, but the pain of doing them by hand has yet to overshadow the time required to develop those features.

These tools are all written in Haskell. If you find them useful, we would love any patches you come up with. We really ought to upload this stuff to hackage, but haven’t for some reason (probably lack of time). I think there is no good reason not too if someone was inclined.

The autobuilder is horribly undocumented, so if you are interested in using it, you will probably need a bit of hand holding to get you started. It’s pretty straight-forward once you know the magic though. I am stepcut on IRC.

Valery V. Vorotyntsev

Step #0: Thanks for the howto!

Step #6: The line could be [25 chars] shorter:

echo '[conf]' | cat - pkg.conf &gt; /tmp/1; mv /tmp/1 pkg.conf

Step #14: Consider updating this step according to your own message to debian-haskell.

Leave a comment