on e920ddf help sign in
haskell.nix/docs/user-guide/stack-projects.md
56 lines 1.4 kB history raw
1Here we will look into how to generate the `pkgs.nix` file for a
2`stack.yaml` project. For the full integration see the
3[previous page](./projects.md).
5## Using `stack-to-nix`
7With [nix-tools installed](../user-guide.md), we can simply run the
8following command on a stack project:
10```bash
11stack-to-nix --output . --stack-yaml stack.yaml
12```
14This will produce a `pkgs.nix` file that looks like the following:
15```nix
17 resolver = "lts-12.17";
18 extras = hackage:
19 {
20 packages = {
21 "o-clock" = hackage.o-clock."0.1.1".revisions.default;
22 ...
23 } // {
24 my-package = ./my-package.nix;
25 ...
26 };
27 };
29```
31This file contains the stackage resolver, as well as set of extra
32packages. The extras specifies which `extra-deps` (here:
33`o-clock-0.1.1`) we wanted to add over the stackage snapshot, and what
34local packages we want (here: `my-package`).
36## Creating the package set
38Import the generated `pkgs.nix` and pass to
39[`mkStackPkgSet`](../reference/library.md#mkstackpkgset) to
40instantiate a package set.
42```nix
43# default.nix
44let
45 # Import the Haskell.nix library,
46 haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
48 # Instantiate a package set using the generated file.
49 pkgSet = haskell.mkStackPkgSet {
50 stack-pkgs = import ./pkgs.nix;
51 pkg-def-overlays = [];
52 modules = [];
53 };
54in
55 pkgSet.config.hsPkgs
56```