Convert stack.yaml files into Nix build instructions.

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

MIT licensed by Jacob Mitchell


Build Status


stack2nix automates conversion from Stack configuration file to Nix expressions.

stack2nix high-level workflow:

  • invoke stack list-dependencies to determine complete fixed version list of packages based on resolver
  • apply any additional configuration (local packages, extra dependencies, etc) from stack.yaml
  • generate complete list of dependencies to Nix expressions, replacing upstream hackage-packages.nix


There are two options. The first is to install stack2nix and its dependencies on your machine directly, and the second is to use the supported virtual machine configuration.

If there are difficulties please file an issue. Generally the virtual machine approach should be more reliable.

Native Environment

  1. Install nix.
  2. Clone this repo.
  3. Run stack install to install.
  4. Ensure cabal2nix v2.2.1 or higher and stack2nix are in your $PATH.

Virtual Machine

  1. Install VirtualBox and Vagrant.
  2. Clone this repo.
  3. Run ./scripts/ and take a coffee break.
  4. If there are no errors, log into the VM: vagrant ssh.


Nix expressions generated by stack2nix depend on a somewhat recent upstream change to nixpkgs. If nix-env or nix-build fails with an error mentioning initialPackages, try setting the NIX_PATH environment variable: NIX_PATH=nixpkgs=

Remote Packages

Stack2nix can generate a nix expressions for Haskell packages hosted in git repositories.

    $ stack2nix --revision 242e2a064f6a32b22e1599bbfe72e64d7b6203b8 > demo.nix
    $ nix-build -A pandoc demo.nix

Local Packages

Sometimes it's convenient to build local Haskell packages. Assuming the current directory is a locally maintained fork of Pandoc:

    $ stack2nix . > default.nix
    $ nix-build -A pandoc


Run ./scripts/ to build and test.

comments powered byDisqus