cabal2nix

Convert Cabal files into Nix build instructions.

https://github.com/nixos/cabal2nix#readme

Version on this page:2.15.1
LTS Haskell 23.0:2.19.1
Stackage Nightly 2024-12-12:2.19.1
Latest on Hackage:2.19.1

See all snapshots cabal2nix appears in

BSD-3-Clause licensed by Peter Simons, Andres Loeh, Benno Fünfstück, Mateusz Kowalczyk, Michael Alan Dorman, Tom Smalley, Mathijs Kwik, Shea Levy, Dmitry Malikov, Eric Seidel, Jacob Mitchell, Graham Christensen, Hamish Mackenzie, Nikolay Amiantov, Aycan iRiCAN, Bryan Gardiner, Joe Hermaszewski, John Wiegley, Philipp Hausmann, Spencer Janssen, Tom Hunger, William Casarin, koral, ksaric, Adam Vogt, Alexey Shmalko, Corey O'Connor, Cray Elliott, David Johnson, Dmitry Bushev, Domen Kožar, Felix Kunzmann, Gabriel Ebner, Gergely Risko, Joachim Fasting, John Albietz, John Chee, Jussi Maki, Lisanna Dettwyler, Mark Laws, Mark Wotton, Matthew Pickering, Matthew Stewart, Matvey Aksenov, Nicholas Clarke, Nicolas Rolland, Oliver Charles, Pascal Wittmann, Patrick John Wheeler, Phil de Joux, Piotr Bogdan, Profpatsch, Raymond Gauthier, Renzo Carbonara, Rodney Lorrimar, Sibi, Sukant Hajra, Tanner Doshier, Vaibhav Sagar, Viktar Basharymau, danbst, karsten gebbert, laMudri, Александр Цамутали
Maintained by Peter Simons
This version can be pinned in stack with:cabal2nix-2.15.1@sha256:37bc3e6e82563ca5ca201c6d756981d05f4b4973de352bdfd24423484061b735,6750

Cabal2nix

hackage release stackage LTS package stackage Nightly package travis build status

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

$ cabal2nix cabal://mtl
{ mkDerivation, base, stdenv, transformers }:
mkDerivation {
  pname = "mtl";
  version = "2.2.1";
  sha256 = "1icdbj2rshzn0m1zz5wa7v3xvkf6qw811p4s7jgqwvx1ydwrvrfa";
  libraryHaskellDepends = [ base transformers ];
  homepage = "http://github.com/ekmett/mtl";
  description = "Monad classes, using functional dependencies";
  license = stdenv.lib.licenses.bsd3;
}

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 still causes network traffic. Run the utility with --help to see the complete list of supported command-line flags.

Detailed instructions on how to use those generated files with Nix can be found at https://nixos.org/nixpkgs/manual/#how-to-create-nix-builds-for-your-own-private-haskell-packages.

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

$ cabal get mtl-2.2.1 && cd mtl-2.2.1
$ cabal2nix .
{ mkDerivation, base, stdenv, transformers }:
mkDerivation {
  pname = "mtl";
  version = "2.2.1";
  src = ./.;
  libraryHaskellDepends = [ base transformers ];
  homepage = "http://github.com/ekmett/mtl";
  description = "Monad classes, using functional dependencies";
  license = stdenv.lib.licenses.bsd3;
}

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 repository types:

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