Home Explore Blog CI



nixpkgs

16th chunk of `doc/languages-frameworks/haskell.section.md`
2cf7d84dadb3151df422b7af8f047e8df8620ed581b53ff30000000100000fa4
`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:

  `extraCabal2nixOptions`
  : Extra command line arguments for `cabal2nix`.

  `srcModifier`
  : A function which is used to modify the given `src` instead of the default
    filter.

    The default source filter will remove all files from `src` except for
    `.cabal` files and `package.yaml` files.

<!--

`callHackage`
: TODO

`callHackageDirect`
: TODO

`developPackage`
: TODO

-->

<!--

TODO(@NixOS/haskell): finish these planned sections
### Overriding the entire package set

## Contributing {#haskell-contributing}

### Fixing a broken package {#haskell-fixing-a-broken-package}


Title: Haskell Package Set Library Functions, Cabal Sdist, and Import-from-Derivation Helpers
Summary
This section describes library functions available in Haskell package sets, including utilities for enabling/disabling library profiling and disabling parallel building. It covers `cabalSdist` for generating Cabal sdist tarballs, `buildFromCabalSdist` for building derivations using the generated sdist, and `generateOptparseApplicativeCompletions` for creating shell completion files. It also introduces import-from-derivation helpers like `cabal2nix` for generating Nix package definitions from Haskell packages, along with `callCabal2nix` and `callCabal2nixWithOptions` for creating packages using `cabal2nix` with customizable options.