From Mandriva Community Wiki

Jump to: navigation, search


Haskell packaging


Haskell modules are normally provides with the Cabal packaging system. This allow to any devellopers to:

  • manage compilation
  • manage modules dependencies
  • install the module
  • produce script to register the module in the compiler database
  • build tarball

So, all haskell module normally have a common scheme about their build

The haskell Cabal

Hackage Database

Haskell devellopers are encouraged to upload their module on the hackage database. Only packages matchings Cabal rules can be upload, moreover some extra checks are performed to ensure the quality of the packages.


Package name

The package name must match the module name prefixed by haskell-.


For many packages, rpm specfile will be similar as they use all the same build system.

So it is really easy to have rpm macros and make the packaging task easy. The package haskell-macros provides a set of macros to help to make rpm packages:

macro usage
%_cabal_build perform the complete build of the haskell module (configure, build, haddock), typically used in %build section
%_cabal_install perform the the installation into the %buildroot (copy), typically use in %install section
%_cabal_check run the test suite of the module, typically use in %check section
%_cabal_genscripts create the and use to register the module on the system
%_cabal_scriptlets this macros is an alias for post install scriptlets, using files created by %_cabal_genscripts

All theses macros assume the cabal startup script provides is named Setup.hs, sometimes it is named Setup.lhs. To override the default value, just redefine %_cabal_setup to the program filename provided with the module:

%define _cabal_setup Setup.lhs


Haskell module have their own dependencies, and it is important to not break it, otherwise you will not be able to use it.

But it is impossible to find theses dependencies from the file installed in the %buildroot.

However the cabal system provides a way to find to find them. So we'll have to provide in the rpm additionnals files only to keep a track of rpm dependencies. haskell-macros provides two rpm macros to do the bad work:

macro usage
%_cabal_rpm_gen_deps to run at the end of %install step, will create a set of files containing our rpm dependencies according cabal information
%_cabal_rpm_files add this macros in the %files section containing modules files (.hi and .o)

Rpm dependencies are created by cabalrpmdeps.

A complete example

specfile of hslogger

%define module filepath

Name: haskell-%{module}
Version: 0.11
Release: %mkrel 4
Summary: Library for manipulating FilePath's in a cross platform way.
Group: Development/Other
License: BSD3
BuildRoot: %_tmppath/%name-%version-%release-root
BuildRequires: haskell-macros
BuildRequires: ghc

Library for manipulating FilePath's in a cross platform way.

%setup -q -n %{module}





rm -fr %{buildroot}/%_datadir/*/doc/



%doc dist/doc/html

rm -fr %buildroot

Comment about this specfile

  • This specfile use cabal, but is not conform to the hackage specification (the tarball is named module_version, not module-version, the builddir is "module", not "module-version"
  • We trash %{buildroot}/%_datadir/*/doc/ to provides files a %doc from the dist/ directory.



  • Only ghc is really supported currently
  • What about biarch ? Is it really usefull ?

To do

One of big improvement would be to support other compilers than ghc, but we are faced to a problem: how to properly build the module for all available compilers ? What are those compilers (not all exist on all architectures).

Related tools

There some projects to write spec files from cabal information. This is a good idea because .cabal files contains everything we need, including buildrequires. Unfortunatelly, no one will match our scheme, but as it is quite easy to, I do plan to do it (Cabal rpm is a start, but should match hackage namespaec policy).

Personal tools