The cabal2nix package

[Tags:bsd3, library, program, test]

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

 nix-env -i cabal2nix

[Skip to Readme]

Properties

Versions 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
Dependencies aeson, ansi-wl-pprint, base (<5), bytestring, Cabal (>1.24), cabal2nix, containers, deepseq (>=1.4), directory, distribution-nixpkgs, filepath, hackage-db, language-nix, lens, monad-par, monad-par-extras, mtl, optparse-applicative, pretty (>=1.1.2), process, SHA, split, text, time, transformers, utf8-string, yaml [details]
License BSD3
Author Peter Simons, Andres Loeh, Benno Fünfstück, Mateusz Kowalczyk, Mathijs Kwik, Michael Alan Dorman, Shea Levy, Dmitry Malikov, Eric Seidel, Nikolay Amiantov, Aycan iRiCAN, John Wiegley, Philipp Hausmann, Spencer Janssen, William Casarin, Adam Vogt, Bryan Gardiner, Corey O'Connor, Cray Elliott, Felix Kunzmann, Gabriel Ebner, Gergely Risko, John Albietz, John Chee, Jussi Maki, Mark Laws, Mark Wotton, Matvey Aksenov, Nicolas Rolland, Oliver Charles, Pascal Wittmann, Patrick John Wheeler, Raymond Gauthier, Renzo Carbonara, Sibi, Tanner Doshier, Tom Hunger, Viktar Basharymau, danbst, karsten gebbert, laMudri, Александр Цамутали
Maintainer Peter Simons <simons@cryp.to>
Stability stable
Category Distribution, Nix
Home page https://github.com/nixos/cabal2nix#readme
Bug tracker https://github.com/nixos/cabal2nix/issues
Source repository head: git clone https://github.com/nixos/cabal2nix
Uploaded Wed Mar 29 10:31:07 UTC 2017 by PeterSimons
Distributions LTSHaskell:2.0.4, NixOS:2.1, Stackage:2.1
Downloads 16492 total (454 in the last 30 days)
Votes
0 []
Status Docs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for cabal2nix

Readme for cabal2nix-2.1.1

Cabal2nix

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

Detailed instructions how to use those generated files with Nix can be found at http://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure.

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:

$ cabal get mtl-2.2.1 && cd mtl-2.2.1
$ cabal2nix .
{ mkDerivation, base, stdenv, transformers }:
mkDerivation {
  pname = "mtl";
  version = "2.2.1";
  src = ./.;
  buildDepends = [ 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 respository types:

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

How to compile this package

The cabal2nix.cabal file for this package is automatically generated by the generate-cabal-file.hs program. The easiest way to accomplish that is to run

nix-shell release.nix -A cabal2nix.ghc7102.x86_64-linux.env --run "runhaskell generate-cabal-file.hs >cabal2nix.cabal"

where x86_64-linux should be replaced with whatever system ID is appropriate for your local machine. Basically, generate-cabal-file.hs requires the cartel library and git to run.

With the Cabal file in place, this is a normal Haskell project that can be compiled with cabal-install.

Users of Nix can build this package by running

nix-build release.nix -A cabal2nix.ghc7102.x86_64-linux

where, again, x86_64-linux should be replaced with the appropriate value. This gives you an executable at result/bin/cabal2nix. If you'd like to install the latest release version, then

nix-env -f "<nixpkgs>" -iA cabal2nix

is the way to go.