cabal2nix: Convert Cabal files into Nix build instructions

[ bsd3, distribution, library, nix, program ] [ Propose Tags ] [ Report a vulnerability ]

This package is no longer maintained on Hackage. Users of Nix can install the latest version by running:

nix-env -i cabal2nix

[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.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, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.1, 2.1.1, 2.2, 2.2.1, 2.3, 2.3.1, 2.4, 2.4.1, 2.5, 2.6, 2.7, 2.7.1, 2.7.2, 2.8, 2.8.1, 2.8.2, 2.9, 2.9.1, 2.9.2, 2.9.3, 2.10.0, 2.10.1, 2.10.2, 2.11, 2.11.1, 2.12, 2.13, 2.14, 2.14.1, 2.14.2, 2.14.3, 2.14.4, 2.15.0, 2.15.1, 2.15.2, 2.15.3, 2.15.4, 2.15.5, 2.15.6, 2.16.0, 2.17.0, 2.18.0, 2.19.0, 2.19.1 (info)
Dependencies base (>=3 && <5), Cabal (>=1.18 && <1.22), containers, deepseq, directory, filepath, hackage-db (>=1.11), mtl, pretty, process, regex-posix, transformers [details]
Tested with ghc >=7.0.4 && <=7.8.3
License BSD-3-Clause
Copyright Peter Simons, Andres Loeh
Author Peter Simons, Andres Loeh
Maintainer Peter Simons <simons@cryp.to>
Revised Revision 5 made by PeterSimons at 2015-06-08T19:57:31Z
Category Distribution
Home page http://github.com/NixOS/cabal2nix
Source repo head: git clone git://github.com/NixOS/cabal2nix.git
Uploaded by PeterSimons at 2015-01-08T11:32:21Z
Distributions LTSHaskell:2.19.1, NixOS:2.19.1, Stackage:2.19.1
Reverse Dependencies 4 direct, 0 indirect [details]
Executables hackage4nix, cabal2nix
Downloads 98523 total (142 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Last success reported on 2015-12-11 [all 9 reports]

Readme for cabal2nix-1.73

[back to package description]

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 extent. 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

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 = "http://www.yesodweb.com/";
    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. However, if the source hash is not already in cabal2nix's cache or provided using the --sha256 option, cabal2nix still needs to download the source code to compute the hash, which obviously still causes network traffic. Run the utility with --help to see the complete list of supported command line flags.

To add a new package to Nix, checkout the Nixpkgs project from https://github.com/nixos/nixpkgs.git and run

$ cd 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 {};

cabal2nix can also build derivations for projects from other sources than hackage. You only need to provide an URI that points to a cabal project. The most common usecase for this is probably to generate a derivation for a project on the local file system:

aeson:$ cabal2nix ./.
# This file was auto-generated by cabal2nix. Please do NOT edit manually!

{ cabal, attoparsec, blazeBuilder, deepseq, dlist, hashable, HUnit
, mtl, QuickCheck, scientific, syb, testFramework
, testFrameworkHunit, testFrameworkQuickcheck2, text, time
, unorderedContainers, vector
}

cabal.mkDerivation (self: {
  pname = "aeson";
  version = "0.7.0.2";
  src = ./.;
  buildDepends = [
    attoparsec blazeBuilder deepseq dlist hashable mtl scientific syb
    text time unorderedContainers vector
  ];
  testDepends = [
    attoparsec HUnit QuickCheck testFramework testFrameworkHunit
    testFrameworkQuickcheck2 text time unorderedContainers vector
  ];
  meta = {
    homepage = "https://github.com/bos/aeson";
    description = "Fast JSON parsing and encoding";
    license = self.stdenv.lib.licenses.bsd3;
    platforms = self.ghc.meta.platforms;
  };
})

This derivation will not fetch from hackage, but instead use the directory which contains the derivation as the source repository.

cabal2nix currently supports the following respository types:

  • directory
  • source archive (zip, tar.gz, ...) from http or https URL or local file.
  • git, mercurial, svn or bazaar repository

Hackage4nix

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 pkgs

in your checked-out copy of the Nixpkgs tree 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 pkgs
The following updates are available:

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

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

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

repa-2.1.1.5:
  cabal2nix cabal://repa-2.1.1.6 >pkgs/pkgs/development/libraries/haskell/repa/default.nix

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

vector-0.7.1:
  cabal2nix cabal://vector-0.8 >pkgs/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, 2013-04-12, virtually all Haskell packages available in Nix have been generated automatically from their Cabal files. There are only a handful of exceptions, which we cannot generate because these packages aren't available on Hackage. The list of those packages is hard-coded into the hackage4nix.hs binary in the function badPackagePaths.

Furthermore, Hackage4Nix will not re-generate packages that have been patched, i.e. that define any of the following attributes:

    (pre|post)Configure
    (pre|post)Install
    patchPhase
    patches

These packages are considered for updates, however.

The complete list of Haskell packages available in Nix is generated by the tool package-list, and published at http://cryp.to/haskell-in-nixpkgs.txt. 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.