Need help with cabal2nix?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

263 Stars 132 Forks Other 2.1K Commits 62 Opened issues


Generate Nix build instructions from a Cabal file

Services available


Need anything else?

Contributors list


hackage release stackage LTS package stackage Nightly package Continous Integration

converts a single Cabal file into a single Nix build expression. For example:
$ cabal2nix cabal://mtl
{ mkDerivation, base, lib, transformers }:
mkDerivation {
  pname = "mtl";
  version = "2.2.1";
  sha256 = "1icdbj2rshzn0m1zz5wa7v3xvkf6qw811p4s7jgqwvx1ydwrvrfa";
  libraryHaskellDepends = [ base transformers ];
  homepage = "";
  description = "Monad classes, using functional dependencies";
  license = lib.licenses.bsd3;

Cabal files can be referred to using the magic URL

, which will automatically download the file from Hackage. Alternatively, a direct
URL can be provided, as well as a
URI that doesn't depend on network access. However, if the source hash is not already in
's cache or provided using the
still needs to download the source code to compute the hash, which still causes network traffic. Run the utility with
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

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, lib, transformers }:
mkDerivation {
  pname = "mtl";
  version = "2.2.1";
  src = ./.;
  libraryHaskellDepends = [ base transformers ];
  homepage = "";
  description = "Monad classes, using functional dependencies";
  license = lib.licenses.bsd3;

This derivation will not fetch from hackage, but instead use the directory which contains the derivation as the source repository.

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


This repository also contains, in the

directory, the tool to update the Haskell packages in nixpkgs. It has its own README there.


is built using
, like you'd expect, and you are free to use your favourite way of setting up a Haskell development environment.


is quite intertwined with the packages
, we recommend setting up a shared development environment for the three packages like so:
$ mkdir /path/to/cabal2nix-root && cd /path/to/cabal2nix-root
$ # clone repositories, note that you may need to checkout an
$ # older tag for some depending on breaking changes on master.
$ git clone
$ git clone
$ git clone
$ # setup development environment with shellFor
$ cat > shell.nix << EOF
# assumes nix{os,pkgs}-unstable
{ pkgs ? import  {} }:

pkgs.haskellPackages.shellFor { packages = p: [ p.cabal2nix-unstable p.distribution-nixpkgs p.hackage-db ];

for running doctests locally

nativeBuildInputs = [ pkgs.haskellPackages.doctest ];

set environment variable, so the development version of

distribution-nixpkgs finds derivation-attr-paths.nix

distribution_nixpkgs_datadir = toString ./distribution-nixpkgs; } EOF $ # tell cabal about local packages $ cat > cabal.project << EOF packages: .//.cabal EOF $ # test our new development environment $ nix-shell --run "cabal v2-build exe:cabal2nix exe:hackage2nix"

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.