Home Explore Blog Models CI



nixpkgs

18th chunk of `doc/languages-frameworks/haskell.section.md`
6fffbb7b7a869f6e96cef818a468aeefd4175428723479f40000000100000a3b
over output size. You may want to…

* …enable profiling globally so that you can build a project you are working on
  with profiling ability giving you insight in the time spent across your code
  and code you depend on using [GHC's profiling feature][profiling].

* …disable profiling (globally) to reduce the time spent building the profiling
  versions of libraries which a significant amount of build time is spent on
  (although they are not as expensive as the “normal” build of a Haskell library).

::: {.note}
The method described below affects the build of all libraries in the
respective Haskell package set as well as GHC. If your choices differ from
Nixpkgs' default for your (host) platform, you will lose the ability to
substitute from the official binary cache.

If you are concerned about build times and thus want to disable profiling, it
probably makes sense to use `haskell.lib.compose.disableLibraryProfiling` (see
[](#haskell-trivial-helpers)) on the packages you are building locally while
continuing to substitute their dependencies and GHC.
:::

Since we need to change the profiling settings for the desired Haskell package
set _and_ GHC (as the core libraries like `base`, `filepath` etc. are bundled
with GHC), it is recommended to use overlays for Nixpkgs to change them.
Since the interrelated parts, i.e. the package set and GHC, are connected
via the Nixpkgs fixpoint, we need to modify them both in a way that preserves
their connection (or else we'd have to wire it up again manually). This is
achieved by changing GHC and the package set in separate overlays to prevent
the package set from pulling in GHC from `prev`.

The result is two overlays like the ones shown below. Adjustable parts are
annotated with comments, as are any optional or alternative ways to achieve
the desired profiling settings without causing too many rebuilds.

<!-- TODO(@sternenseemann): buildHaskellPackages != haskellPackages with this overlay,
affected by https://github.com/NixOS/nixpkgs/issues/235960 which needs to be fixed
properly still.
-->

```nix
let
  # Name of the compiler and package set you want to change. If you are using
  # the default package set `haskellPackages`, you need to look up what version
  # of GHC it currently uses (note that this is subject to change).
  ghcName = "ghc910";
  # Desired new setting
  enableProfiling = true;

in
[
  # The first overlay modifies the GHC derivation so that it does or does not
  # build profiling versions of the core libraries bundled with it. It is
  # recommended to only use such an overlay if you are enabling profiling on a

Title: Configuring Global Haskell Profiling with Nixpkgs Overlays
Summary
This section details how to enable or disable global profiling for Haskell libraries and GHC within Nixpkgs. It explains that while profiling offers performance insights, enabling it globally increases build times, and any deviation from default settings means losing the ability to substitute from the official binary cache. The recommended method for adjusting profiling settings is through Nixpkgs overlays, specifically using two separate overlays to modify GHC and the Haskell package set independently, ensuring their interconnectedness is preserved. An example configuration demonstrating this approach with `ghcName` and `enableProfiling` variables is provided.