Generate Nix build instructions from a Cabal file
Go to file
Peter Simons 722a3771a7 The <> operator was added to Prelude in base-4.9.x.
We depend on base-4.11.x, so there's no need to explicitly import Data.Monoid.
2020-03-13 22:02:27 +01:00
cabal2nix Migrate cabal2nix's Main module to a library-exposed module. 2017-06-06 10:34:05 -07:00
doc Fix some typos. 2018-07-04 10:10:10 +02:00
hackage2nix ghc-8.10.x warns about "import Data.List" without an import list. 2020-03-13 22:02:05 +01:00
src The <> operator was added to Prelude in base-4.9.x. 2020-03-13 22:02:27 +01:00
test Revert "Revert "Disable Haddock phase for packages with internal libraries."" 2019-02-18 08:50:03 +01:00
.gitignore git: ignore Cabal's new-style environment files 2017-09-06 09:19:24 +02:00
.travis.yml travis-ci: run build tests with ghc-8.8.3 instead of 8.8.2 2020-03-13 20:47:15 +01:00
cabal2nix.cabal cabal2nix.cabal: drop redundant constraints on Cabal in the executables 2020-03-13 22:01:21 +01:00
LICENSE travis: switch CI builds from Stack to cabal-install 2016-06-15 18:53:48 +02:00
README.md README.md: improve spelling and grammar 2019-10-30 15:48:58 +01:00
Setup.hs Run doctests on Travis, not via Cabal. 2018-01-20 20:34:13 +01:00
update-hackage-snapshot.sh update-hackage-snapshot.sh: update hackage db snapshot nix Nixpkgs 2018-02-22 15:49:50 +01:00
update-nixpkgs.sh Fix some typos. 2018-07-04 10:10:10 +02:00
update-stackage.sh update-stackage: I no longer maintain lambdabot, so let's stick to Stackage here 2020-01-10 20:43:03 +01:00

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