Home Explore Blog Models CI



nixpkgs

16th chunk of `doc/languages-frameworks/haskell.section.md`
0b654c2bc8d35325291044939b09b7d26aefbb8755d249300000000100000fc8
environment is missing the dependencies necessary for compiling the
benchmark component.

`dontBenchmark drv`
: Set `doBenchmark` to `false` for `drv`.

`setBuildTargets drv list`
: Sets the `buildTarget` argument for `drv` so that the targets specified in `list` are built.

`doCoverage drv`
: Sets the `doCoverage` argument to `true` for `drv`.

`dontCoverage drv`
: Sets the `doCoverage` argument to `false` for `drv`.

`enableExecutableProfiling drv`
: Sets the `enableExecutableProfiling` argument to `true` for `drv`.

`disableExecutableProfiling drv`
: Sets the `enableExecutableProfiling` argument to `false` for `drv`.

`enableLibraryProfiling drv`
: Sets the `enableLibraryProfiling` argument to `true` for `drv`.

`disableLibraryProfiling drv`
: Sets the `enableLibraryProfiling` argument to `false` for `drv`.

`disableParallelBuilding drv`
: Sets the `enableParallelBuilding` argument to `false` for `drv`.

#### Library functions in the Haskell package sets {#haskell-package-set-lib-functions}

Some library functions depend on packages from the Haskell package sets. Thus they are
exposed from those instead of from `haskell.lib.compose` which can only access what is
passed directly to it. When using the functions below, make sure that you are obtaining them
from the same package set (`haskellPackages`, `haskell.packages.ghc944` etc.) as the packages
you are working with or – even better – from the `self`/`final` fix point of your overlay to
`haskellPackages`.

Note: Some functions like `shellFor` that are not intended for overriding per se, are omitted
in this section. <!-- TODO(@sternenseemann): note about ifd section -->

`cabalSdist { src, name ? ... }`
: Generates the Cabal sdist tarball for `src`, suitable for uploading to Hackage.
Contrary to `haskell.lib.compose.sdistTarball`, it uses `cabal-install` over `Setup.hs`,
so it is usually faster: No build dependencies need to be downloaded, and we can
skip compiling `Setup.hs`.

`buildFromCabalSdist drv`
: Build `drv`, but run its `src` attribute through `cabalSdist` first. Useful for catching
files necessary for compilation that are missing from the sdist.

`generateOptparseApplicativeCompletions list drv`
: Generate and install shell completion files for the installed executables whose
names are given via `list`. The executables need to be using `optparse-applicative`
for [this to work][optparse-applicative-completions].
Note that this feature is automatically disabled when cross-compiling, since it
requires executing the binaries in question.

## Import-from-Derivation helpers {#haskell-import-from-derivation}

### cabal2nix {#haskell-cabal2nix}

[`cabal2nix`][cabal2nix] can generate Nix package definitions for arbitrary
Haskell packages using [import from derivation][import-from-derivation].
`cabal2nix` will generate Nix expressions that look like this:

```nix
# cabal get mtl-2.2.1 && cd mtl-2.2.1 && cabal2nix .
{
  mkDerivation,
  base,
  lib,
  transformers,
}:
mkDerivation {
  pname = "mtl";
  version = "2.2.1";
  src = ./.;
  libraryHaskellDepends = [
    base
    transformers
  ];
  homepage = "http://github.com/ekmett/mtl";
  description = "Monad classes, using functional dependencies";
  license = lib.licenses.bsd3;
}
```

This expression should be called with `haskellPackages.callPackage`, which will
supply [`haskellPackages.mkDerivation`](#haskell-mkderivation) and the Haskell
dependencies as arguments.

`callCabal2nix name src args`
: Create a package named `name` from the source derivation `src` using
  `cabal2nix`.

  `args` are extra arguments provided to `haskellPackages.callPackage`.

`callCabal2nixWithOptions name src opts args`
: Create a package named `name` from the source derivation `src` using
  `cabal2nix`.

  `opts` are extra options for calling `cabal2nix`. If `opts` is a string, it
  will be used as extra command line arguments for `cabal2nix`, e.g. `--subpath
  path/to/dir/containing/cabal-file`. Otherwise, `opts` should be an AttrSet
  which can contain the following attributes:

Title: Nix Haskell Library Functions and `cabal2nix` Integration
Summary
This chunk concludes the list of Nix Haskell helper functions, covering build controls like benchmarking, build targets, code coverage, profiling, and parallel building. It then introduces 'Library functions in the Haskell package sets,' including `cabalSdist` for efficient Cabal source distribution generation, `buildFromCabalSdist`, and `generateOptparseApplicativeCompletions` for shell completions. The document transitions to 'Import-from-Derivation helpers', detailing `cabal2nix`. It explains how `cabal2nix` generates Nix package definitions from Haskell projects, providing an output example. Finally, it describes `callCabal2nix` for creating packages from source with `cabal2nix` and additional `callPackage` arguments, along with `callCabal2nixWithOptions` for passing extra `cabal2nix` command-line or attribute set options.