1Haskell.nix also provides reproducible development environments for
2your Haskell projects. These environments can contain not only GHC and
3your Haskell package dependencies, but also the required system
4libraries and build tools.
6Inside the development shell, you can run commands such as `ghc`,
7`ghci`, or `cabal new‑build`, and they will have all dependencies
10Every dependency will be cached in your Nix store. If you have set up
11Hydra CI, then your team can share pre-built dependencies.
13These examples assume that you have created your package set as
14described in [Creating Nix builds for your projects](projects.md) and
15it exists in a file called `default.nix`.
19 Old-style `cabal build` and `stack` builds are not (yet)
20 supported. For example, `stack` will (by design) download and
21 rebuild all dependencies, even though they are available in the
22 shell. However, if you have a Stack project, you can generate the
23 package set with Haskell.nix, then use `cabal new‑build` to work
26## How to get a development shell for a package
28Run a `nix‑shell` on `components.all` of your package. `all` is a
29synthetic component whose dependencies are the union of the
30dependencies of all components in the package. Therefore, you will be
31able to build the test suites because their dependencies will be
37 hsPkgs = import ./default.nix {};
39 hsPkgs.my-package.components.all
42## How to get a development shell for a multi-package project
44If you have a Cabal or Stack project with multiple packages
45(i.e. multiple `.cabal` files, not a single package with multiple
46components), then you will need a development environment that
47contains the _dependencies_ of your packages, but not the packages
48themselves. This is what the `shellFor` function does.
52{ pkgs ? import <nixpkgs> {} };
55 hsPkgs = import ./default.nix { inherit pkgs; };
58 # Include only the *local* packages of your project.
59 packages = ps: with ps; [
64 # Builds a Hoogle documentation index of all dependencies,
65 # and provides a "hoogle" command to search the index.
68 # You might want some extra tools in the shell (optional).
69 buildInputs = with pkgs.haskellPackages;
70 [ hlint stylish-haskell ghcid ];
74## How to get an ad-hoc development shell including certain packages
76This creates a development environment with the given packages
77registered in the package database. The `ghcWithPackages` function
78operates on a Haskell.nix package set, and accepts an argument that
79selects packages from the larger package set.
84 haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
86 haskell.haskellPackages.ghcWithPackages (ps: with ps;
87 [ lens conduit conduit-extra ])
90If you need a Hoogle documentation index, use `ghcWithHoogle` in place
93## How to get packages from a certain Stackage snapshot
95Haskell.nix knows about every released Stackage snapshot. You can use
96it to build packages from a given snapshot, without setting up a full
101 haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
103 haskell.snapshots."lts-13.18".alex.components.exes.alex
106There are Haskell.nix package sets for every Stackage snaphot under
109The alias `haskell.haskellPackages` corresponds to the package set for
110a recent LTS Haskell version.
112You can use `ghcWithPackages` on any of these package sets to quickly
113get a shell with some packages.
116 The build will not work if your Nixpkgs does not contain the version
117 of GHC specified in the snapshot. Nixpkgs only carries the
118 latest version of each recent release series, so many snapshots
124Once you have a development shell, then you can begin configuring
125Emacs to use it. The way I do it is:
1271. Run [lorri watch](https://github.com/target/lorri) to continously
128 build the shell environment and maintain GC roots.
1302. Use [emacs‑direnv](https://github.com/wbolster/emacs-direnv) to
131 push the development environment into Emacs.
1333. Use [Dante](https://github.com/jyp/dante) for highlighting errors
134 and auto-completion. You must customize Dante to prevent it from
135 automatically using `nix‑shell` or `stack`. Trim `dante‑methods` to
136 just `new‑build` and `bare‑ghci`.
138 You can also use [`.dir‑locals.el`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html)
139 for this. If your project has multiple targets, set `dante‑target`
1424. For [`haskell‑mode`](https://github.com/haskell/haskell-mode)
143 interactive Haskell, set `haskell‑process‑type` to
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list