The cabal2nix package

[Tags: bsd3, deprecated, program]


The cabal2nix utility converts Cabal files into Nix build instructions. The commandline syntax is:

 Usage: cabal2nix [options] url-to-cabal-file
   -h             --help                   show this help text
                  --sha256=HASH            sha256 hash of source tarball
   -m MAINTAINER  --maintainer=MAINTAINER  maintainer of this package (may be specified multiple times)
   -p PLATFORM    --platform=PLATFORM      supported build platforms (may be specified multiple times)

 Recognized URI schemes:

   cabal://pkgname-pkgversion       download the specified package from Hackage
   http://host/path                 fetch the Cabal file via HTTP
   file:///local/path               load the Cabal file from the local disk
   /local/path                      abbreviated version of file URI

The only required argument is the path to the cabal file. For example:

 cabal2nix cabal://cabal2nix-1.25

If the --sha256 option has not been specified, cabal2nix calls nix-prefetch-url to determine the hash automatically. This causes network traffic, obviously.

[Skip to ReadMe]


Versions1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.20, 1.21, 1.23, 1.24, 1.25, 1.26, 1.27, 1.28, 1.29, 1.30, 1.31, 1.32, 1.33, 1.34, 1.35, 1.37, 1.38, 1.39, 1.40, 1.41, 1.42, 1.43, 1.44, 1.45, 1.46, 1.47, 1.48, 1.49, 1.50, 1.51, 1.52, 1.53, 1.54, 1.55, 1.56, 1.57, 1.58, 1.59, 1.60, 1.61, 1.63, 1.64, 1.65, 1.66, 1.67, 1.68, 1.69, 1.70, 1.71, 1.72, 1.73
Change logNone available
Dependenciesbase (>=3 && <5), Cabal (>=1.8), containers, directory, filepath, hackage-db, HTTP, mtl, nixos-types (>=1.2), pretty, process, regex-posix [details]
CopyrightPeter Simons, Andres Loeh
AuthorPeter Simons <>, Andres Loeh <>
MaintainerNix Developers <>
Home page
Source repositoryhead: git clone git://
Executableshackage4nix, cabal2nix
UploadedFri Feb 3 20:55:05 UTC 2012 by PeterSimons
Downloads11804 total (449 in last 30 days)
0 []
StatusDocs not available [build log]
All reported builds failed as of 2015-10-06 [all 3 reports]


Maintainers' corner

For package maintainers and hackage trustees

Readme for cabal2nix-1.25

How to maintain Haskell Packages in Nix

Overview over the tool-chain

There are two utilities, cabal2nix and hackage4nix, that automate maintenance to a large extend. We intend to merge them into one program, eventually, but the necessary re-factoring hasn't been done yet since this is not a high priority.


cabal2nix converts a single Cabal file into a single Nix build expression. For example:

$ cabal2nix cabal://yesod-0.9.1
{ cabal, attoparsecText, blazeBuilder, blazeHtml, hamlet, httpTypes
, monadControl, parsec, shakespeareCss, shakespeareJs, text, time
, transformers, unixCompat, wai, waiExtra, warp, yesodAuth
, yesodCore, yesodForm, yesodJson, yesodPersistent

cabal.mkDerivation (self: {
  pname = "yesod";
  version = "0.9.1";
  sha256 = "1ag3lca75lrriycbscspb5yyishacgxjx0rybc3x4z1dqnkn1r71";
  isLibrary = true;
  isExecutable = true;
  buildDepends = [
    attoparsecText blazeBuilder blazeHtml hamlet httpTypes monadControl
    parsec shakespeareCss shakespeareJs text time transformers
    unixCompat wai waiExtra warp yesodAuth yesodCore yesodForm
    yesodJson yesodPersistent
  meta = {
    homepage = "";
    description = "Creation of type-safe, RESTful web applications";
    license = self.stdenv.lib.licenses.bsd3;
    platforms = self.ghc.meta.platforms;

Cabal files can be referred to using the magic URL cabal://NAME-VERSION, which will automatically download the file from Hackage. Alternatively, a direct http://host/path/pkg.cabal URL can be provided, as well as a file:///local/path/pkg.cabal URI that doesn't depend on network access. Run the utility with --help to see the complete list of supported command line flags.

To add a new package to Nix, the following steps need to be performed:

$ cd $NIXPKGS_ALL/pkgs/development/libraries/haskell
$ mkdir foo
$ cabal2nix cabal://foo-1.0 >foo/default.nix

Then add an appropriate attribute to pkgs/top-level/haskell-packages.nix, for example:

foo = callPackage ../development/libraries/haskell/foo {};


The hackage4nix utility re-generates all expressions found in the nixpkgs database in place. This is useful to ensure that all packages have been generated with a recent version of the tool-chain. Furthermore, hackage4nix adds default settings for the meta.maintainers and meta.platforms attribute if these aren't configured yet. Generally speaking, running

$ hackage4nix $NIXPKGS_ALL

should be a no-op --- i.e. no files should change! If there are changes, these indicate that a file has been modified manually, and then these changes must be investigated to find out what is going on.

Last but not least, hackage4nix generates a list of all updates available from Hackage. (Run cabal update to make sure that your local copy of the Hackage database is up-to-date!) For example:

$ hackage4nix $NIXPKGS_ALL
The following updates are available:

  cabal2nix cabal://WebBits-Html-1.0.2 >$NIXPKGS_ALL/pkgs/development/libraries/haskell/WebBits-Html/default.nix

  cabal2nix cabal://happstack-server-6.2.1 >$NIXPKGS_ALL/pkgs/development/libraries/haskell/happstack/happstack-server.nix
  cabal2nix cabal://happstack-server-6.2.2 >$NIXPKGS_ALL/pkgs/development/libraries/haskell/happstack/happstack-server.nix

  cabal2nix cabal://primitive-0.4 >$NIXPKGS_ALL/pkgs/development/libraries/haskell/primitive/default.nix

  cabal2nix cabal://repa- >$NIXPKGS_ALL/pkgs/development/libraries/haskell/repa/default.nix

  cabal2nix cabal://unix-compat-0.3 >$NIXPKGS_ALL/pkgs/development/libraries/haskell/unix-compat/default.nix

  cabal2nix cabal://vector-0.8 >$NIXPKGS_ALL/pkgs/development/libraries/haskell/vector/default.nix

These updates can be performed automatically by running the cabal2nix command given by hackage4nix. If there is more than one possible update, then all of them will be shown. Note, however, that some updates break compilation of other packages, because they depend on very specific versions of their build inputs, so please be careful when performing updates!

Current State of Affairs

The tool-chain is stable. As of today, 2011-08-30, almost all Haskell packages available in Nix have been generated automatically from their Cabal files. The exceptions are:

The complete list of Haskell packages available in Nix is generated by the tool package-list, and published at Hackage picks it up from there and generates links on each package's homepage to the corresponding page in Hydra automatically. See ticket 875 for further details.