summaryrefslogtreecommitdiff
path: root/pkgs/test/haskell/incremental/default.nix
blob: 329346d9ce831fe3b4928ef911e41b98c2ac1361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Demonstration of incremental builds for Haskell. Useful for speeding up CI.
#
# See: https://www.haskellforall.com/2022/12/nixpkgs-support-for-incremental-haskell.html
# See: https://felixspringer.xyz/homepage/blog/incrementalHaskellBuildsWithNix

{
  haskell,
  haskellPackages,
  lib,
}:

let
  inherit (haskell.lib.compose) overrideCabal;

  # Incremental builds work with GHC >=9.4.
  temporary = haskellPackages.temporary;

  # This will do a full build of `temporary`, while writing the intermediate build products
  # (compiled modules, etc.) to the `intermediates` output.
  temporary-full-build-with-incremental-output = overrideCabal (drv: {
    doInstallIntermediates = true;
    enableSeparateIntermediatesOutput = true;
  }) temporary;

  # This will do an incremental build of `temporary` by copying the previously
  # compiled modules and intermediate build products into the source tree
  # before running the build.
  #
  # GHC will then naturally pick up and reuse these products, making this build
  # complete much more quickly than the previous one.
  temporary-incremental-build = overrideCabal (drv: {
    previousIntermediates = temporary-full-build-with-incremental-output.intermediates;
  }) temporary;
in
temporary-incremental-build.overrideAttrs (old: {
  meta = old.meta // {
    maintainers = old.meta.maintainers or [ ] ++ [
      lib.maintainers._9999years
      lib.maintainers.Gabriella439
      lib.maintainers.lf-
    ];
  };
})