cabal2nix: Convert Cabal files into Nix build instructions.

[ bsd3, distribution, library, nix, program ] [ Propose Tags ]

Convert Cabal files into Nix build instructions. Users of Nix can install the latest version by running:

nix-env -i cabal2nix

[Skip to Readme]
Versions [faq] 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 (info)
Dependencies aeson (>1), ansi-wl-pprint, base (>4.11 && <5), bytestring, Cabal (>=3.0), cabal2nix, containers (>=0.5.9), deepseq (>=1.4), directory, distribution-nixpkgs (>=1.3.1), filepath, hackage-db (>=2.0.1), hopenssl (>=2), hpack (>=0.29.6), language-nix, lens, monad-par, monad-par-extras, mtl, optparse-applicative, pretty (>=1.1.2), process, split, text, time, transformers, yaml [details]
License BSD-3-Clause
Author 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, Александр Цамутали
Maintainer Peter Simons <simons@cryp.to>
Category Distribution, Nix
Home page https://github.com/nixos/cabal2nix#readme
Bug tracker https://github.com/nixos/cabal2nix/issues
Source repo head: git clone https://github.com/nixos/cabal2nix
Uploaded by PeterSimons at 2020-06-13T11:31:46Z
Distributions LTSHaskell:2.12, NixOS:2.15.5, Stackage:2.14.3
Executables hackage2nix, cabal2nix
Downloads 77415 total (2815 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs not available [build log]
All reported builds failed as of 2020-06-13 [all 3 reports]

Modules

  • Cabal2nix
  • Distribution
    • Nixpkgs
      • Distribution.Nixpkgs.Fetch
      • Distribution.Nixpkgs.Haskell
        • Distribution.Nixpkgs.Haskell.BuildInfo
        • Distribution.Nixpkgs.Haskell.Constraint
        • Distribution.Nixpkgs.Haskell.Derivation
        • Distribution.Nixpkgs.Haskell.FromCabal
          • Distribution.Nixpkgs.Haskell.FromCabal.Configuration
          • Distribution.Nixpkgs.Haskell.FromCabal.Flags
          • Distribution.Nixpkgs.Haskell.FromCabal.License
          • Distribution.Nixpkgs.Haskell.FromCabal.Name
          • Distribution.Nixpkgs.Haskell.FromCabal.Normalize
          • Distribution.Nixpkgs.Haskell.FromCabal.PostProcess
        • Distribution.Nixpkgs.Haskell.Hackage
        • Distribution.Nixpkgs.Haskell.OrphanInstances
        • Distribution.Nixpkgs.Haskell.PackageSourceSpec

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for cabal2nix-2.15.5

[back to package description]

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

hackage2nix

This repository also contains, in the hackage2nix/ directory, the tool to update the Haskell packages in nixpkgs. It has its own README there.

Building

For ease of contribution, we support these methods to build cabal2nix:

  • stack build if you have Stack
    • The Stack build can use system dependencies from a pinned nixpkgs version for increased reproducibility (see stack.yaml). On NixOS this happens automatically. On non-NixOS, use stack --nix build for that.
  • cabal install if you have cabal-install installed
  • TODO: Add a build method that requires only nix preinstalled, also pins nixpkgs, and is thus fully reproducible.

When making changes, please ensure that all these methods continue to work.