From cd5e16917d86334e6801ccb2387d49a5eb21d1f6 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 11 Mar 2023 12:19:42 +0100 Subject: [PATCH] Add trivial source filter to avoid rebuilds --- CHANGELOG.md | 1 + nix/haskell-project.nix | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 267b8a1..29701eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - #92: Add `devShell.mkShellArgs` to pass custom arguments to `mkShell` - #111: Add `devShell.extraLibraries` to add custom Haskell libraries to the devshell. - #100: `source-overrides` option now supports specifying Hackage versions. + - #114: Prevent Nix rebuilds of packages in sub-directories when parent contents change. - API changes - #37: Group `buildTools` (renamed to `tools`), `hlsCheck` and `hlintCheck` under the `devShell` submodule option; and allow disabling them all using `devShell.enable = false;` (useful if you want haskell-flake to produce just the package outputs). - #64: Remove hlintCheck (use [treefmt-nix](https://github.com/numtide/treefmt-nix#flake-parts) instead) diff --git a/nix/haskell-project.nix b/nix/haskell-project.nix index deb7981..0afc23d 100644 --- a/nix/haskell-project.nix +++ b/nix/haskell-project.nix @@ -58,14 +58,31 @@ in hpack '' else root; + setSrc = name: root: pkg: hlib.overrideSrc { + src = + lib.cleanSourceWith { + name = "source-${name}-${pkg.version}"; + src = + # NOTE: Even though cabal2nix does run hpack automatically, + # buildFromCabalSdist does not. So we must run hpack ourselves at + # the original source level. + realiseHpack name root; + }; + } pkg; in lib.mapAttrs - (name: value: - # NOTE: Even though cabal2nix does run hpack automatically, - # buildFromCabalSdist does not. So we must run hpack ourselves at - # the original source level. - let root = realiseHpack name value.root; - in fromSdist (self.callCabal2nix name root { }) + (name: pkgCfg: + lib.pipe pkgCfg + [ + (pkgCfg: self.callCabal2nix name pkgCfg.root { }) + + # Avoid rebuilding because of changes in parent directories + (setSrc name pkgCfg.root) + + # Make sure all files we use are included in the sdist, as a check + # for release-worthiness. + fromSdist + ] ) config.packages;