about summary refs log tree commit diff
path: root/nixpkgs/pkgs/test/haskell/incremental
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/test/haskell/incremental')
-rw-r--r--nixpkgs/pkgs/test/haskell/incremental/default.nix35
1 files changed, 35 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/test/haskell/incremental/default.nix b/nixpkgs/pkgs/test/haskell/incremental/default.nix
new file mode 100644
index 000000000000..4509939ba4f4
--- /dev/null
+++ b/nixpkgs/pkgs/test/haskell/incremental/default.nix
@@ -0,0 +1,35 @@
+# 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.
+  temporary = haskell.packages.ghc944.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 = {
+      maintainers = lib.teams.mercury.members;
+    };
+  })