1# Demonstration of incremental builds for Haskell. Useful for speeding up CI.
2#
3# See: https://www.haskellforall.com/2022/12/nixpkgs-support-for-incremental-haskell.html
4# See: https://felixspringer.xyz/homepage/blog/incrementalHaskellBuildsWithNix
5
6{
7 haskell,
8 haskellPackages,
9 lib,
10}:
11
12let
13 inherit (haskell.lib.compose) overrideCabal;
14
15 # Incremental builds work with GHC >=9.4.
16 temporary = haskellPackages.temporary;
17
18 # This will do a full build of `temporary`, while writing the intermediate build products
19 # (compiled modules, etc.) to the `intermediates` output.
20 temporary-full-build-with-incremental-output = overrideCabal (drv: {
21 doInstallIntermediates = true;
22 enableSeparateIntermediatesOutput = true;
23 }) temporary;
24
25 # This will do an incremental build of `temporary` by copying the previously
26 # compiled modules and intermediate build products into the source tree
27 # before running the build.
28 #
29 # GHC will then naturally pick up and reuse these products, making this build
30 # complete much more quickly than the previous one.
31 temporary-incremental-build = overrideCabal (drv: {
32 previousIntermediates = temporary-full-build-with-incremental-output.intermediates;
33 }) temporary;
34in
35temporary-incremental-build.overrideAttrs (old: {
36 meta = {
37 teams = [ lib.teams.mercury ];
38 };
39})