1[Haskell.nix][] contains a library of functions for creating buildable
2package sets from their Nix expression descriptions. The library is
3what you get when importing [Haskell.nix][]. It might be helpful to
4load the library in the [Nix REPL](../user-guide.md#using-nix-repl) to
7 * [Types](#types) — the kinds of data that you will encounter working with [Haskell.nix][].
8 * [Top-level attributes](#top-level-attributes) — Functions and derivations defined in the Haskell.nix attrset.
9 * [Package-set functions](#package-set-functions) — Helper functions defined on the `hsPkgs` package set.
15The result of `mkPkgSet`. This is an application of the NixOS module
33| Attribute | Type | Description |
34|----------------|------|-----------------------------------------------------|
35| `options` | Module options | The combination of all options set through the `modules` argument passed to `mkPkgsSet`. |
36| `config` | | The result of evaluating and applying the `options` with [Haskell.nix][] |
37| `.hsPkgs` | Attrset of [Haskell Packages](#haskell-package) | Buildable packages, created from `packages` |
38| `.packages` | Attrset of [Haskell Package descriptions](#haskell-package-descriptions) | Configuration for each package in `hsPkgs` |
39| `.compiler` | Attrset | |
43## Haskell Package description
45The _Haskell package descriptions_ are values of the
46`pkgSet.config.packages` attrset. These are not derivations, but just
47the configuration for building an individual package. The
48configuration options are described under `packages.<name>` in [Module
49options](./modules.md).
51## Component description
53The _component descriptions_ are values of the
54`pkgSet.config.packages.<package>.components` attrset. These are not
55derivations, but just the configuration for building an individual
56component. The configuration options are described under
57`packages.<name>.components.*` in [Module options](./modules.md).
62In [Haskell.nix][], a _Haskell package_ is a derivation which has a
63`components` attribute. This derivation is actually just for the
64package `Setup.hs` script, and isn't very interesting. To actually use
65the package, look within the components structure.
70 exes = { NAME = COMPONENT; };
71 tests = { NAME = COMPONENT; };
72 benchmarks = { NAME = COMPONENT; };
79In [Haskell.nix][], a _component_ is a derivation corresponding to a
80[Cabal component](https://www.haskell.org/cabal/users-guide/developing-packages.html)
83[Haskell.nix][] also defines a special `all` component, which is the
84union of all components in the package.
88A package identifier is an attrset pair of `name` and `version`.
92Extras allow adding more packages to the package set. These will be
93functions taking a single parameter `hackage`. They should return an
94attrset of package descriptions.
98Modules are the primary method of configuring building of the package
1011. an attrset containing [option declarations](./options.md), or
1022. a function that returns an attrset containing option declarations.
104If using the function form of a module, the following named parameters
107| Argument | Type | Description |
108|------------------|------|---------------------|
109| `haskellLib` | attrset | The [haskellLib](#haskelllib) utility functions. |
110| `pkgs` | | The Nixpkgs collection. |
111| `pkgconfPkgs` | | A mapping of cabal build-depends names to Nixpkgs packages. (TODO: more information about this) |
112| `buildModules` | | |
117# Top-level attributes
121Creates a [package set](#package-set) based on the `pkgs.nix` output
126 { stack-pkgs, pkg-def-extras ? [], modules ? []}: ...
129| Argument | Type | Description |
130|------------------|------|---------------------|
131| `stack-pkgs` | | `import ./pkgs.nix` — The imported file generated by `stack‑to‑nix`. |
132| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
133| `modules` | List of [Modules](#modules) | For overriding the package set. |
135**Return value**: a [`pkgSet`](#package-set)
137## mkCabalProjectPkgSet
139Creates a [package set](#package-set) based on the `pkgs.nix` output
143mkCabalProjectPkgSet =
144 { plan-pkgs, pkg-def-extras ? [], modules ? []}: ...
147| Argument | Type | Description |
148|------------------|------|---------------------|
149| `plan-pkgs` | | `import ./pkgs.nix` — The imported file generated by `plan‑to‑nix`. |
150| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
151| `modules` | List of [Modules](#modules) | For overriding the package set. |
153**Return value**: a [`pkgSet`](#package-set)
157This is the base function used by both `mkStackPkgSet` and
158`mkCabalProjectPkgSet`.
160**Return value**: a [`pkgSet`](#package-set)
164This is an attrset of `hsPkgs` packages from Stackage.
168A `hsPkgs` package set, which is one of the recent LTS Haskell
169releases from [`snapshots`](#snapshots).
171The chosen LTS is updated occasionally in [Haskell.nix][], though a
176A derivation containing the `nix-tools` [command-line tools](commands.md).
180Runs `stack-to-nix` and produces the output needed for
181`importAndFilterProject`.
186 pkgSet = mkStackPkgSet {
187 stack-pkgs = (importAndFilterProject (callStackToNix {
196## callCabalProjectToNix
198Runs `cabal new-configure` and `plan-to-nix` and produces the output
199needed for `importAndFilterProject`.
204 pkgSet = mkCabalProjectPkgSet {
205 plan-pkgs = (importAndFilterProject (callCabalProjectToNix {
206 index-state = "2019-04-30T00:00:00Z";
211| Argument | Type | Description |
212|------------------|------|---------------------|
213| `name` | String | Optional name for better error messages. |
214| `src` | Path | Location of the cabal project files. |
215| `index-state` | Timestamp | Optional hackage index-state, eg. "2019-10-10T00:00:00Z". |
216| `index-sha256` | Sha256 | Optional hash of the truncated hackage index-state. |
217| `plan-sha256` | Sha256 | Optional hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation). |
218| `cabalProject` | Path | Optional cabal project file (defaults to "${src}/cabal.project"). |
219| `ghc` | | Optional ghc to use |
220| `nix-tools` | | Optional nix-tools to use |
221| `hpack` | | Optional hpack to use |
222| `cabal-install` | | Optional cabal-install to use |
223| `configureArgs` | String | Optional extra arguments to pass to `cabal new-configure` (--enable-tests is included by default, include `--disable-tests` to override that). |
225## importAndFilterProject
227Imports from a derivation created by `callStackToNix`
228or `callCabalProjectToNix`.
230The result is an attrset with the following values:
232| Attribute | Type | Description |
233|----------------|------|-----------------------------------------------------|
234| `pkgs` | attrset | that can be passed to `mkStackPkgSet` (as `stack-pkgs`) or `mkCabalProjectPkgSet` (as `plan-pkgs`). |
235| `nix` | | this can be built and cached so that the amount built in the evaluation phase is not too great (helps to avoid timeouts on Hydra). |
245cleanSourceHaskell = { src, name ? null }: ...
248Filters a source tree removing common filenames that are not Haskell
251This can avoid unecessary rebuilds when these files change.
253It's recommended to provide `name` so that the source derivation
254remains constant regardless of how it was fetched.
259src = pkgs.haskell-nix.cleanSourceHaskell {
261 name = "myproject-src";
265## haskellSourceFilter
268haskellSourceFilter = name: type: ...
271This is a source filter function which cleans common build products
272and files not needed to do a Haskell build from a source directory.
274It should be used with `pkgs.lib.cleanSourceWith`. Alternatively,
275use the convenience function [`cleanSourceHaskell`](#cleansourcehaskell).
280Assorted functions for operating on [Haskell.nix][] data. This is
281distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell
284### collectComponents and collectComponents'
286Extracts a selection of components from a Haskell [package set](#package-set).
288This can be used to filter out all test suites or benchmarks of
289your project, so that they can be built in Hydra (see check if you
290want to run the tests as well as build them).
292`collectComponents'` is an alias of `collectComponents` without
293predicate for filtering.
297 group: packageSel: haskellPackages: ...
298collectComponents' = group: collectComponents (_: true)
302| Argument | Type | Description |
303|-------------------|--------|---------------------|
304| `group` | String | A [sub-component type](#subComponentTypes). |
305| `packageSel` | A function `Package -> Bool` | A predicate to filter packages with. |
306| `haskellPackages` | [Package set](#package-set) | All packages in the build. |
308**Return value**: a recursive attrset mapping package names → component names → components.
313tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs;
316Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests`
317to `tests.mypackage.unit-tests`.
321This function turns a derivation that builds a test into one to run it.
323| Argument | Type | Description |
324|-------------------|--------|---------------------|
325| `drv` | Derivation | One of `$pkg.components.tests.$test`. |
327For convenience `$pkg.components.tests` are mapped with this function
330This function is intended for use with `tests` but it should also work
331for `exes` and `benchmarks` if you just want to run them to make sure
334#### subComponentTypes
336Sub-component types identify [components](#component) and are one of:
344# Package-set functions
346These functions exist within the `hsPkgs` package set.
350Create a `nix-shell` [development
351environment](../user-guide/development.md) for developing one or more
352packages with `ghci` or `cabal v2-build` (but not Stack).
356 { packages, withHoogle ? true, exactDeps ? false, ...}: ...
360| Argument | Type | Description |
361|----------------|------|---------------------|
362| `packages` | Function | Package selection function. It takes a list of [Haskell packages](#haskell-package) and returns a subset of these packages. |
363| `withHoogle` | Boolean | Whether to build a Hoogle documentation index and provide the `hoogle` command. |
364| `exactDeps` | Boolean | Prevents the Cabal solver from choosing any package dependency other than what are in the package set. |
365| `{ ... }` | Attrset | All the other arguments are passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv). |
367**Return value**: a derivation
371 `exactDeps = true` will set the `CABAL_CONFIG` environment variable
372 to disable remote package servers. This is a
373 [known limitation](../dev/removing-with-package-wrapper.md)
374 which we would like to solve. Use `exactDeps = false` if this is a
380Creates a `nix-shell` [development
381environment](../user-guide/development.md) including the given
382packages selected from this package set.
384**Parameter**: a package selection function.
386**Return value**: a derivation
391haskell.haskellPackages.ghcWithPackages (ps: with ps; [ lens conduit ])
396The same as `ghcWithPackages`, except, a `hoogle` command with a
397Hoogle documentation index of the packages will be included in the
400[haskell.nix]: https://github.com/input-output-hk/haskell.nix
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