mirror of
https://github.com/simplex-chat/haskell.nix.git
synced 2026-06-03 09:17:32 +00:00
The docs are not complete yet, but we can start improving them from here.
57 lines
1.4 KiB
Markdown
57 lines
1.4 KiB
Markdown
Here we will look into how to generate the `pkgs.nix` file for a
|
|
`stack.yaml` project. For the full integration see the
|
|
[previous page](./projects.md).
|
|
|
|
## Using `stack-to-nix`
|
|
|
|
With [nix-tools installed](../user-guide.md), we can simply run the
|
|
following command on a stack project:
|
|
|
|
```bash
|
|
stack-to-nix --output . --stack-yaml stack.yaml
|
|
```
|
|
|
|
This will produce a `pkgs.nix` file that looks like the following:
|
|
```nix
|
|
{
|
|
resolver = "lts-12.17";
|
|
extras = hackage:
|
|
{
|
|
packages = {
|
|
"o-clock" = hackage.o-clock."0.1.1".revisions.default;
|
|
...
|
|
} // {
|
|
my-package = ./my-package.nix;
|
|
...
|
|
};
|
|
};
|
|
}
|
|
```
|
|
|
|
This file contains the stackage resolver, as well as set of extra
|
|
packages. The extras specifies which `extra-deps` (here:
|
|
`o-clock-0.1.1`) we wanted to add over the stackage snapshot, and what
|
|
local packages we want (here: `my-package`).
|
|
|
|
## Creating the package set
|
|
|
|
Import the generated `pkgs.nix` and pass to
|
|
[`mkStackPkgSet`](../reference/library.md#mkstackpkgset) to
|
|
instantiate a package set.
|
|
|
|
```nix
|
|
# default.nix
|
|
let
|
|
# Import the Haskell.nix library,
|
|
haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
|
|
|
|
# Instantiate a package set using the generated file.
|
|
pkgSet = haskell.mkStackPkgSet {
|
|
stack-pkgs = import ./pkgs.nix;
|
|
pkg-def-overlays = [];
|
|
modules = [];
|
|
};
|
|
in
|
|
pkgSet.config.hsPkgs
|
|
```
|