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 |
170## project, cabalProject and stackProject
172These versions of the function are the same as project', cabalProject'
173and stackProject', but `hsPkgs` attributes are also included in the
174return value directly. That way a package can be referenced as
175`(project {...}).foo` instead of `(project' {...}).hsPkgs.foo`.
179Creates a [package set](#package-set) based on the `pkgs.nix` output
184 { stack-pkgs, pkg-def-extras ? [], modules ? []}: ...
187| Argument | Type | Description |
188|------------------|------|---------------------|
189| `stack-pkgs` | | `import ./pkgs.nix` — The imported file generated by `stack‑to‑nix`. |
190| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
191| `modules` | List of [Modules](#modules) | For overriding the package set. |
193**Return value**: a [`pkgSet`](#package-set)
195## mkCabalProjectPkgSet
197Creates a [package set](#package-set) based on the `pkgs.nix` output
201mkCabalProjectPkgSet =
202 { plan-pkgs, pkg-def-extras ? [], modules ? []}: ...
205| Argument | Type | Description |
206|------------------|------|---------------------|
207| `plan-pkgs` | | `import ./pkgs.nix` — The imported file generated by `plan‑to‑nix`. |
208| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
209| `modules` | List of [Modules](#modules) | For overriding the package set. |
211**Return value**: a [`pkgSet`](#package-set)
215This is the base function used by both `mkStackPkgSet` and
216`mkCabalProjectPkgSet`.
218**Return value**: a [`pkgSet`](#package-set)
222This is an attrset of `hsPkgs` packages from Stackage.
226A `hsPkgs` package set, which is one of the recent LTS Haskell
227releases from [`snapshots`](#snapshots).
229The chosen LTS is updated occasionally in [Haskell.nix][], though a
234A derivation containing the `nix-tools` [command-line tools](commands.md).
238Runs `stack-to-nix` and produces the output needed for
239`importAndFilterProject`.
244 pkgSet = mkStackPkgSet {
245 stack-pkgs = (importAndFilterProject (callStackToNix {
254## callCabalProjectToNix
256Runs `cabal new-configure` and `plan-to-nix` and produces the output
257needed for `importAndFilterProject`.
262 pkgSet = mkCabalProjectPkgSet {
263 plan-pkgs = (importAndFilterProject (callCabalProjectToNix {
264 index-state = "2019-04-30T00:00:00Z";
269| Argument | Type | Description |
270|----------------------|------|---------------------|
271| `name` | String | Optional name for better error messages. |
272| `src` | Path | Location of the cabal project files. |
273| `compiler-nix-name` | String | The name of the ghc compiler to use eg. "ghc884" |
274| `index-state` | Timestamp | Optional hackage index-state, eg. "2019-10-10T00:00:00Z". |
275| `index-sha256` | Sha256 | Optional hash of the truncated hackage index-state. |
276| `plan-sha256` | Sha256 | Optional hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation). |
277| `cabalProject` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project"). |
278| `cabalProjectLocal` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project.local"). |
279| `cabalProjectFreeze` | String | Optional cabal project file contents (defaults to readFile "${src}/cabal.project.freeze"). |
280| `ghc` | | Deprecated. Use `compiler-nix-name` instead. Optional ghc to use |
281| `nix-tools` | | Optional nix-tools to use |
282| `hpack` | | Optional hpack to use |
283| `cabal-install` | | Optional cabal-install to use |
284| `configureArgs` | String | Optional extra arguments to pass to `cabal new-configure` (--enable-tests is included by default, include `--disable-tests` to override that). |
286## importAndFilterProject
288Imports from a derivation created by `callStackToNix`
289or `callCabalProjectToNix`.
291The result is an attrset with the following values:
293| Attribute | Type | Description |
294|----------------|------|-----------------------------------------------------|
295| `pkgs` | attrset | that can be passed to `mkStackPkgSet` (as `stack-pkgs`) or `mkCabalProjectPkgSet` (as `plan-pkgs`). |
296| `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). |
306cleanSourceHaskell = { src, name ? null }: ...
309Filters a source tree removing common filenames that are not Haskell
312This can avoid unecessary rebuilds when these files change.
314It's recommended to provide `name` so that the source derivation
315remains constant regardless of how it was fetched.
320src = pkgs.haskell-nix.cleanSourceHaskell {
322 name = "myproject-src";
326## haskellSourceFilter
329haskellSourceFilter = name: type: ...
332This is a source filter function which cleans common build products
333and files not needed to do a Haskell build from a source directory.
335It should be used with `pkgs.lib.cleanSourceWith`. Alternatively,
336use the convenience function [`cleanSourceHaskell`](#cleansourcehaskell).
341Assorted functions for operating on [Haskell.nix][] data. This is
342distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell
345### collectComponents, collectComponents'
347Extracts a selection of components from a Haskell [package set](#package-set).
349This can be used to filter out all test suites or benchmarks of
350your project, so that they can be built in Hydra (see check if you
351want to run the tests as well as build them).
353`collectComponents'` is an alias of `collectComponents` without
354predicate for filtering.
358 group: packageSel: haskellPackages: ...
359collectComponents' = group: collectComponents (_: true)
363| Argument | Type | Description |
364|-------------------|--------|---------------------|
365| `group` | String | A [sub-component type](#subComponentTypes). |
366| `packageSel` | A function `Package -> Bool` | A predicate to filter packages with. |
367| `haskellPackages` | [Package set](#package-set) | All packages in the build. |
369**Return value**: a recursive attrset mapping package names → component names → components.
374tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs;
377Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests`
378to `tests.mypackage.unit-tests`.
380### collectChecks, collectChecks'
382These are just like `collectComponents` and `collectComponents'`, except that they collect
383the `checks` attributes of packages (which aren't components, and so can't be collected
384by the other functions.
388This function turns a derivation that builds a test into one to run it.
390| Argument | Type | Description |
391|-------------------|--------|---------------------|
392| `drv` | Derivation | One of `$pkg.components.tests.$test`. |
394For convenience `$pkg.components.tests` are mapped with this function
397This function is intended for use with `tests` but it should also work
398for `exes` and `benchmarks` if you just want to run them to make sure
401#### subComponentTypes
403Sub-component types identify [components](#component) and are one of:
413These functions are included in the `project` return values.
414In the past they also existed within `project.hsPkgs`,
415but have now been removed from there.
419Create a `nix-shell` [development
420environment](../tutorials/development.md) for developing one or more
421packages with `ghci` or `cabal v2-build` (but not Stack).
425 { packages, withHoogle ? true, exactDeps ? false, ...}: ...
429| Argument | Type | Description |
430|----------------|------|---------------------|
431| `packages` | Function | Package selection function. It takes a list of [Haskell packages](#haskell-package) and returns a subset of these packages. |
432| `components` | Function | Similar to `packages`, by default all the components of the selected packages are selected. |
433| `additional` | Function | Similar to `packages`, but the selected packages are built and included in `ghc-pkg list` (not just their dependencies). |
434| `withHoogle` | Boolean | Whether to build a Hoogle documentation index and provide the `hoogle` command. |
435| `exactDeps` | Boolean | Prevents the Cabal solver from choosing any package dependency other than what are in the package set. |
436| `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. |
437| `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).
438| `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). |
439| `{ ... }` | Attrset | All the other arguments are passed to [`mkDerivation`](https://nixos.org/nixpkgs/manual/#sec-using-stdenv). |
441**Return value**: a derivation
445 `exactDeps = true` will set the `CABAL_CONFIG` environment variable
446 to disable remote package servers. This is a
447 [known limitation](../dev/removing-with-package-wrapper.md)
448 which we would like to solve. Use `exactDeps = false` if this is a
454Creates a `nix-shell` [development
455environment](../tutorials/development.md) including the given
456packages selected from this package set.
458**Parameter**: a package selection function.
460**Return value**: a derivation
465haskell.haskellPackages.ghcWithPackages (ps: with ps; [ lens conduit ])
470The same as `ghcWithPackages`, except, a `hoogle` command with a
471Hoogle documentation index of the packages will be included in the
474[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