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](../tutorials/development.md#using-nix-repl) to
7 * [Data structures](#data-structures) — 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; };
78In [Haskell.nix][], a _component_ is a derivation corresponding to a
79[Cabal component](https://www.haskell.org/cabal/users-guide/developing-packages.html)
84A package identifier is an attrset pair of `name` and `version`.
88Extras allow adding more packages to the package set. These will be
89functions taking a single parameter `hackage`. They should return an
90attrset of package descriptions.
94Modules are the primary method of configuring building of the package
971. an attrset containing [option declarations](./modules.md), or
982. a function that returns an attrset containing option declarations.
100If using the function form of a module, the following named parameters
103| Argument | Type | Description |
104|------------------|------|---------------------|
105| `haskellLib` | attrset | The [haskellLib](#haskelllib) utility functions. |
106| `pkgs` | | The Nixpkgs collection. |
107| `pkgconfPkgs` | | A mapping of cabal build-depends names to Nixpkgs packages. (TODO: more information about this) |
108| `buildModules` | | |
113# Top-level attributes
117Function that accepts attribute set with a `src` attribute and looks for `stack.yaml` file relative to it.
119If file exists, it calls [stackProject](#stackproject') function. Otherwise it will call [cabalProject](#cabalproject') function.
124pkgs.haskell-nix.project' {
125 # 'cleanGit' cleans a source directory based on the files known by git
126 src = pkgs.haskell-nix.haskellLib.cleanGit {
127 name = "haskell-nix-project";
135A function calling [callStackToNix](#callstacktonix) with all arguments.
137Then feeding its result into [mkStackPkgSet](#mkstackpkgset) passing also
138`pkg-def-extras` and `modules` arguments.
142| Attribute | Type | Description |
143|-------------------|--------------------------------------------------|----------------------------------------------------------------------------|
144| `hsPkgs` | Attrset of [Haskell Packages](#haskell-package) | Buildable packages, created from `packages` |
145| `stack-nix` | | `projectNix` attribute of [`callStackToNix`](#callstacktonix) return value |
146| `shellFor` | Function | [`shellFor`](#shellfor) |
147| `ghcWithHoogle` | Function | [`ghcWithHoogle`](#ghcwithhoogle) |
148| `ghcWithPackages` | Function | [`ghcWithPackages`](#ghcwithpackages) |
153A function calling [callCabalProjectToNix](#callcabalprojecttonix) with all arguments.
155Then feeding its result into [mkCabalProjectPkgSet](#mkcabalprojectpkgset) passing also
156`pkg-def-extras`, `extra-hackages` and `modules` arguments.
160| Attribute | Type | Description |
161|-------------------|--------------------------------------------------|-----------------------------------------------------------------------------|
162| `hsPkgs` | Attrset of [Haskell Packages](#haskell-package) | Buildable packages, created from `packages` |
163| `plan-nix` | | `projectNix` attribute of [`callCabalProjectToNix`](#callcabalprojecttonix) return value |
164| `index-state` | | `index-state` attribute of [`callCabalProjectToNix`](#callcabalprojecttonix) return value |
165| `shellFor` | Function | [`shellFor`](#shellfor) |
166| `ghcWithHoogle` | Function | [`ghcWithHoogle`](#ghcwithhoogle) |
167| `ghcWithPackages` | Function | [`ghcWithPackages`](#ghcwithpackages) |
168| `projectCross` | Attrset | Like `pkgs.pkgsCross.<system>` from nixpkgs `p.projectCross.<system>` returns the project results for cross compilation (where system is a member of nixpkgs lib.systems.examples). So `p.projectCross.ghcjs.hsPkgs` is the same as `hsPkgs` but compiled with ghcjs |
169| `appendModule` | Function | Re-eval the project with an extra module (or module list). |
171## project, cabalProject and stackProject
173These versions of the function are the same as project', cabalProject'
174and stackProject', but `hsPkgs` attributes are also included in the
175return value directly. That way a package can be referenced as
176`(project {...}).foo` instead of `(project' {...}).hsPkgs.foo`.
180Creates a [package set](#package-set) based on the `pkgs.nix` output
185 { stack-pkgs, pkg-def-extras ? [], modules ? []}: ...
188| Argument | Type | Description |
189|------------------|------|---------------------|
190| `stack-pkgs` | | `import ./pkgs.nix` — The imported file generated by `stack‑to‑nix`. |
191| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
192| `modules` | List of [Modules](#modules) | For overriding the package set. |
194**Return value**: a [`pkgSet`](#package-set)
196## mkCabalProjectPkgSet
198Creates a [package set](#package-set) based on the `pkgs.nix` output
202mkCabalProjectPkgSet =
203 { plan-pkgs, pkg-def-extras ? [], modules ? []}: ...
206| Argument | Type | Description |
207|------------------|------|---------------------|
208| `plan-pkgs` | | `import ./pkgs.nix` — The imported file generated by `plan‑to‑nix`. |
209| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
210| `modules` | List of [Modules](#modules) | For overriding the package set. |
212**Return value**: a [`pkgSet`](#package-set)
216This is the base function used by both `mkStackPkgSet` and
217`mkCabalProjectPkgSet`.
219**Return value**: a [`pkgSet`](#package-set)
223This is an attrset of `hsPkgs` packages from Stackage.
227A `hsPkgs` package set, which is one of the recent LTS Haskell
228releases from [`snapshots`](#snapshots).
230The chosen LTS is updated occasionally in [Haskell.nix][], though a
235A derivation containing the `nix-tools` [command-line tools](commands.md).
239Runs `stack-to-nix` and produces the output needed for
240`importAndFilterProject`.
245 pkgSet = mkStackPkgSet {
246 stack-pkgs = (importAndFilterProject (callStackToNix {
255## callCabalProjectToNix
257Runs `cabal new-configure` and `plan-to-nix` and produces the output
258needed for `importAndFilterProject`.
263 pkgSet = mkCabalProjectPkgSet {
264 plan-pkgs = (importAndFilterProject (callCabalProjectToNix {
265 index-state = "2019-04-30T00:00:00Z";
270| Argument | Type | Description |
271|----------------------|------|---------------------|
272| `name` | String | Optional name for better error messages. |
273| `src` | Path | Location of the cabal project files. |
274| `compiler-nix-name` | String | The name of the ghc compiler to use eg. "ghc884" |
275| `index-state` | Timestamp | Optional hackage index-state, eg. "2019-10-10T00:00:00Z". |
276| `index-sha256` | Sha256 | Optional hash of the truncated hackage index-state. |
277| `plan-sha256` | Sha256 | Optional hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation). |
278| `cabalProject` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project"). |
279| `cabalProjectLocal` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project.local"). |
280| `cabalProjectFreeze` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project.freeze"). |
281| `ghc` | | Deprecated. Use `compiler-nix-name` instead. Optional ghc to use |
282| `nix-tools` | | Optional nix-tools to use |
283| `hpack` | | Optional hpack to use |
284| `cabal-install` | | Optional cabal-install to use |
285| `configureArgs` | String | Optional extra arguments to pass to `cabal new-configure` (--enable-tests is included by default, include `--disable-tests` to override that). |
287## importAndFilterProject
289Imports from a derivation created by `callStackToNix`
290or `callCabalProjectToNix`.
292The result is an attrset with the following values:
294| Attribute | Type | Description |
295|----------------|------|-----------------------------------------------------|
296| `pkgs` | attrset | that can be passed to `mkStackPkgSet` (as `stack-pkgs`) or `mkCabalProjectPkgSet` (as `plan-pkgs`). |
297| `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). |
307cleanSourceHaskell = { src, name ? null }: ...
310Filters a source tree removing common filenames that are not Haskell
313This can avoid unecessary rebuilds when these files change.
315It's recommended to provide `name` so that the source derivation
316remains constant regardless of how it was fetched.
321src = pkgs.haskell-nix.cleanSourceHaskell {
323 name = "myproject-src";
327## haskellSourceFilter
330haskellSourceFilter = name: type: ...
333This is a source filter function which cleans common build products
334and files not needed to do a Haskell build from a source directory.
336It should be used with `pkgs.lib.cleanSourceWith`. Alternatively,
337use the convenience function [`cleanSourceHaskell`](#cleansourcehaskell).
342Assorted functions for operating on [Haskell.nix][] data. This is
343distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell
346### collectComponents, collectComponents'
348Extracts a selection of components from a Haskell [package set](#package-set).
350This can be used to filter out all test suites or benchmarks of
351your project, so that they can be built in Hydra (see check if you
352want to run the tests as well as build them).
354`collectComponents'` is an alias of `collectComponents` without
355predicate for filtering.
359 group: packageSel: haskellPackages: ...
360collectComponents' = group: collectComponents (_: true)
364| Argument | Type | Description |
365|-------------------|--------|---------------------|
366| `group` | String | A [sub-component type](#subComponentTypes). |
367| `packageSel` | A function `Package -> Bool` | A predicate to filter packages with. |
368| `haskellPackages` | [Package set](#package-set) | All packages in the build. |
370**Return value**: a recursive attrset mapping package names → component names → components.
375tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs;
378Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests`
379to `tests.mypackage.unit-tests`.
381### collectChecks, collectChecks'
383These are just like `collectComponents` and `collectComponents'`, except that they collect
384the `checks` attributes of packages (which aren't components, and so can't be collected
385by the other functions.
389This function turns a derivation that builds a test into one to run it.
391| Argument | Type | Description |
392|-------------------|--------|---------------------|
393| `drv` | Derivation | One of `$pkg.components.tests.$test`. |
395For convenience `$pkg.components.tests` are mapped with this function
398This function is intended for use with `tests` but it should also work
399for `exes` and `benchmarks` if you just want to run them to make sure
402#### subComponentTypes
404Sub-component types identify [components](#component) and are one of:
414These functions are included in the `project` return values.
415In the past they also existed within `project.hsPkgs`,
416but have now been removed from there.
420Create a `nix-shell` [development
421environment](../tutorials/development.md) for developing one or more
422packages with `ghci` or `cabal v2-build` (but not Stack).
426 { packages, withHoogle ? true, exactDeps ? false, ...}: ...
430| Argument | Type | Description |
431|----------------|------|---------------------|
432| `packages` | Function | Package selection function. It takes a list of [Haskell packages](#haskell-package) and returns a subset of these packages. |
433| `components` | Function | Similar to `packages`, by default all the components of the selected packages are selected. |
434| `additional` | Function | Similar to `packages`, but the selected packages are built and included in `ghc-pkg list` (not just their dependencies). |
435| `withHoogle` | Boolean | Whether to build a Hoogle documentation index and provide the `hoogle` command. |
436| `exactDeps` | Boolean | Prevents the Cabal solver from choosing any package dependency other than what are in the package set. |
437| `tools` | Function | AttrSet of tools to make available e.g. `{ cabal = "3.2.0.0"; }` or `{ cabal = { version = "3.2.0.0"; }; }`. If an AttrSet is provided for a tool, the additional arguments will be passed to the function creating the derivation for that tool. So you can provide an `index-state` or a `materialized` argument like that `{ cabal = { version = "3.2.0.0"; index-state = "2020-10-30T00:00:00Z"; materialized = ./cabal.materialized; }; }` for example. You can specify and materialize the version of hoogle used to construct the hoogle index by including something like `{ hoogle = { version = "5.0.17.15"; index-state = "2020-05-31T00:00:00Z"; materialized = ./hoogle.materialized; }`. Uses a default version of hoogle if omitted. |
438| `inputsFrom` | List | List of other shells to include in this one. The `buildInputs` and `nativeBuildInputs` of each will be included using [mkShell](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell).
439| `crossPlatforms` | Function | Platform selection function for cross compilation targets to support eg. `ps: with ps; [ghcjs mingwW64]` (see nixpkgs lib.systems.examples for list of platform names). |
440| `{ ... }` | Attrset | All the other arguments are passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv). |
442**Return value**: a derivation
446 `exactDeps = true` will set the `CABAL_CONFIG` environment variable
447 to disable remote package servers. This is a
448 [known limitation](../dev/removing-with-package-wrapper.md)
449 which we would like to solve. Use `exactDeps = false` if this is a
455Creates a `nix-shell` [development
456environment](../tutorials/development.md) including the given
457packages selected from this package set.
459**Parameter**: a package selection function.
461**Return value**: a derivation
466haskell.haskellPackages.ghcWithPackages (ps: with ps; [ lens conduit ])
471The same as `ghcWithPackages`, except, a `hoogle` command with a
472Hoogle documentation index of the packages will be included in the
475[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