* docs: Fix notes about .nix-tools.cache Relates to #57 * docs: Add note about Cabal 2.4 requirement Fixes #164 * docs: Autogenerate module option reference * docs: Update library reference * Buildkite: enable docs build on branches
7.2 KiB
Haskell.nix contains a library of functions for creating buildable package sets from their Nix expression descriptions. The library is what you get when importing Haskell.nix. It might be helpful to load the library in the Nix REPL to test things.
- Types — the kinds of data that you will encounter working with Haskell.nix.
- Top-level attributes — Functions and derivations defined in the Haskell.nix attrset.
- Package-set functions — Helper functions defined on the
hsPkgspackage set.
Types
Package Set
The result of mkPkgSet. This is an application of the NixOS module
system.
{
options = { ... };
config = {
hsPkgs = { ... };
packages = { ... };
compiler = {
version = "X.Y.Z";
nix-name = "ghcXYZ";
packages = { ... };
};
};
}
| Attribute | Type | Description |
|---|---|---|
options |
Module options | The combination of all options set through the modules argument passed to mkPkgsSet. |
config |
The result of evaluating and applying the options with Haskell.nix |
|
.hsPkgs |
Attrset of Haskell Packages | Buildable packages, created from packages |
.packages |
Attrset of Haskell Package descriptions | Configuration for each package in hsPkgs |
.compiler |
Attrset |
Haskell Package description
The Haskell package descriptions are values of the
pkgSet.config.packages attrset. These are not derivations, but just
the configuration for building an individual package. The
configuration options are described under packages.<name> in Module
options.
Component description
The component descriptions are values of the
pkgSet.config.packages.<package>.components attrset. These are not
derivations, but just the configuration for building an individual
component. The configuration options are described under
packages.<name>.components.* in Module options.
Haskell Package
In Haskell.nix, a Haskell package is a derivation which has a
components attribute. This derivation is actually just for the
package Setup.hs script, and isn't very interesting. To actually use
the package, look within the components structure.
components = {
library = COMPONENT;
exes = { NAME = COMPONENT; };
tests = { NAME = COMPONENT; };
benchmarks = { NAME = COMPONENT; };
all = COMPONENT;
}
Component
In Haskell.nix, a component is a derivation corresponding to a Cabal component of a package.
Haskell.nix also defines a special all component, which is the
union of all components in the package.
Identifier
A package identifier is an attrset pair of name and version.
Extras
Extras allow adding more packages to the package set. These will be
functions taking a single parameter hackage. They should return an
attrset of package descriptions.
Modules
Modules are the primary method of configuring building of the package set. They are either:
- an attrset containing option declarations, or
- a function that returns an attrset containing option declarations.
If using the function form of a module, the following named parameters will be passed to it:
| Argument | Type | Description |
|---|---|---|
haskellLib |
attrset | The haskellLib utility functions. |
pkgs |
The Nixpkgs collection. | |
pkgconfPkgs |
A mapping of cabal build-depends names to Nixpkgs packages. (TODO: more information about this) | |
buildModules |
||
config |
||
options |
Top-level attributes
mkStackPkgSet
Creates a package set based on the pkgs.nix output
of stack-to-nix.
mkStackPkgSet =
{ stack-pkgs, pkg-def-extras ? [], modules ? []}: ...
| Argument | Type | Description |
|---|---|---|
stack-pkgs |
import ./pkgs.nix — The imported file generated by stack‑to‑nix. |
|
pkg‑def‑extras |
List of Extras | For overriding the package set. |
modules |
List of Modules | For overriding the package set. |
Return value: a pkgSet
mkCabalProjectPkgSet
Creates a package set based on the pkgs.nix output
of plan-to-nix.
mkCabalProjectPkgSet =
{ plan-pkgs, pkg-def-extras ? [], modules ? []}: ...
| Argument | Type | Description |
|---|---|---|
plan-pkgs |
import ./pkgs.nix — The imported file generated by plan‑to‑nix. |
|
pkg‑def‑extras |
List of Extras | For overriding the package set. |
modules |
List of Modules | For overriding the package set. |
Return value: a pkgSet
mkPkgSet
This is the base function used by both mkStackPkgSet and
mkCabalProjectPkgSet.
Return value: a pkgSet
snapshots
This is an attrset of hsPkgs packages from Stackage.
haskellPackages
A hsPkgs package set, which is one of the recent LTS Haskell
releases from snapshots.
The chosen LTS is updated occasionally in Haskell.nix, though a manual process.
nix-tools
A derivation containing the nix-tools command-line tools.
callStackToNix
callCabalProjectToNix
hackage
stackage
fetchExternal
cleanSourceHaskell
haskellLib
Assorted functions for operating on Haskell.nix data. This is
distinct from pkgs.haskell.lib in the current Nixpkgs Haskell
Infrastructure.
Package-set functions
These functions exist within the hsPkgs package set.
shellFor
Create a nix-shell development
environment for developing one or more
packages.
shellFor =
{ packages, withHoogle ? true, ...}: ...
| Argument | Type | Description |
|---|---|---|
packages |
Function | Package selection function. It takes a list of Haskell packages and returns a subset of these packages. |
withHoogle |
Boolean | Whether to build a Hoogle documentation index and provide the hoogle command. |
{ ... } |
Attrset | All the other arguments are passed to mkDerivation. |
Return value: a derivation
ghcWithPackages
Creates a nix-shell development
environment including the given
packages selected from this package set.
Parameter: a package selection function.
Return value: a derivation
Example:
haskell.haskellPackages.ghcWithPackages (ps: with ps; [ lens conduit ])
ghcWithHoogle
The same as ghcWithPackages, except, a hoogle command with a
Hoogle documentation index of the packages will be included in the
shell.