git.iko.soy/typeable/cabal2nix
on v2.0.2 help sign in
84 lines 3.4 kB history raw
1Cabal2nix
2=========
4`cabal2nix` converts a single Cabal file into a single Nix build expression.
5For example:
7 $ cabal2nix cabal://mtl
8 { mkDerivation, base, stdenv, transformers }:
9 mkDerivation {
10 pname = "mtl";
11 version = "2.2.1";
12 sha256 = "1icdbj2rshzn0m1zz5wa7v3xvkf6qw811p4s7jgqwvx1ydwrvrfa";
13 buildDepends = [ base transformers ];
14 homepage = "http://github.com/ekmett/mtl";
15 description = "Monad classes, using functional dependencies";
16 license = stdenv.lib.licenses.bsd3;
17 }
20Cabal files can be referred to using the magic URL `cabal://NAME-VERSION`,
21which will automatically download the file from Hackage. Alternatively, a
22direct `http://host/path/pkg.cabal` URL can be provided, as well as a
23`file:///local/path/pkg.cabal` URI that doesn't depend on network access.
24However, if the source hash is not already in `cabal2nix`'s cache or provided
25using the `--sha256` option, `cabal2nix` still needs to download the source
26code to compute the hash, which obviously still causes network traffic. Run the
27utility with `--help` to see the complete list of supported command line flags.
29Detailed instructions how to use those generated files with Nix can be found at
30http://hydra.nixos.org/job/nixpkgs/trunk/manual/latest/download-by-type/doc/manual#users-guide-to-the-haskell-infrastructure.
32`cabal2nix` can also build derivations for projects from other sources than
33hackage. You only need to provide an URI that points to a cabal project. The
34most common usecase for this is probably to generate a derivation for a project
35on the local file system:
37 $ cabal get mtl-2.2.1 && cd mtl-2.2.1
38 $ cabal2nix .
39 { mkDerivation, base, stdenv, transformers }:
40 mkDerivation {
41 pname = "mtl";
42 version = "2.2.1";
43 src = ./.;
44 buildDepends = [ base transformers ];
45 homepage = "http://github.com/ekmett/mtl";
46 description = "Monad classes, using functional dependencies";
47 license = stdenv.lib.licenses.bsd3;
48 }
50This derivation will not fetch from hackage, but instead use the directory which
51contains the derivation as the source repository.
53`cabal2nix` currently supports the following respository types:
55* directory
56* source archive (zip, tar.gz, ...) from http or https URL or local file.
57* git, mercurial, svn or bazaar repository
59How to compile this package
60---------------------------
62The `cabal2nix.cabal` file for this package is automatically generated by the
63`generate-cabal-file.hs` program. The easiest way to accomplish that is to run
65 nix-shell release.nix -A cabal2nix.ghc7102.x86_64-linux.env --run "runhaskell generate-cabal-file.hs >cabal2nix.cabal"
67where `x86_64-linux` should be replaced with whatever system ID is appropriate
68for your local machine. Basically, `generate-cabal-file.hs` requires the
69[cartel](http://hackage.haskell.org/package/cartel) library and `git` to run.
71With the Cabal file in place, this is a normal Haskell project that can be
72compiled with `cabal-install`.
74Users of Nix can build this package by running
76 nix-build release.nix -A cabal2nix.ghc7102.x86_64-linux
78where, again, `x86_64-linux` should be replaced with the appropriate value.
79This gives you an executable at `result/bin/cabal2nix`. If you'd like to
80install the latest release version, then
82 nix-env -f "<nixpkgs>" -iA cabal2nix
84is the way to go.