2023-04-20 19:59:32 +00:00
|
|
|
# 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, lib }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (haskell.lib.compose) overrideCabal;
|
|
|
|
|
|
|
|
# Incremental builds work with GHC >=9.4.
|
2023-05-30 00:06:42 +00:00
|
|
|
temporary = haskell.packages.ghc944.temporary;
|
2023-04-20 19:59:32 +00:00
|
|
|
|
2023-05-30 00:06:42 +00:00
|
|
|
# This will do a full build of `temporary`, while writing the intermediate build products
|
2023-04-20 19:59:32 +00:00
|
|
|
# (compiled modules, etc.) to the `intermediates` output.
|
2023-05-30 00:06:42 +00:00
|
|
|
temporary-full-build-with-incremental-output = overrideCabal (drv: {
|
2023-04-20 19:59:32 +00:00
|
|
|
doInstallIntermediates = true;
|
|
|
|
enableSeparateIntermediatesOutput = true;
|
2023-05-30 00:06:42 +00:00
|
|
|
}) temporary;
|
2023-04-20 19:59:32 +00:00
|
|
|
|
2023-05-30 00:06:42 +00:00
|
|
|
# This will do an incremental build of `temporary` by copying the previously
|
2023-04-20 19:59:32 +00:00
|
|
|
# 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.
|
2023-05-30 00:06:42 +00:00
|
|
|
temporary-incremental-build = overrideCabal (drv: {
|
|
|
|
previousIntermediates = temporary-full-build-with-incremental-output.intermediates;
|
|
|
|
}) temporary;
|
2023-04-20 19:59:32 +00:00
|
|
|
in
|
2023-05-30 00:06:42 +00:00
|
|
|
temporary-incremental-build.overrideAttrs (old: {
|
2023-04-20 19:59:32 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.mercury.members;
|
|
|
|
};
|
|
|
|
})
|