From f2409bd62f6c3179f344921452189bf8720cdc50 Mon Sep 17 00:00:00 2001 From: jappeace-sloth Date: Sat, 6 Jun 2026 23:27:41 +0200 Subject: [PATCH] Filter source with lib.fileset to stop nix files invalidating builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces `callCabal2nix "template-project" ../. {}` with an explicit `lib.fileset.toSource` that unions only app/, src/, test/, the cabal file, LICENSE, Readme.md and Changelog.md. This addresses the existing note that nix/tooling files were considered for the build, and so the cabal2nix-driven derivation no longer rebuilds when shell.nix, nix/hpkgs.nix, .github/, makefile, .hlint.yaml etc. change. Verified locally with `nix-build` — template-1.0.0 builds and the unit test suite (5 tests) passes. Prompt: go update my haskell-template-project, I want find grained source filtereing like this: [lib.fileset.toSource snippet] Tokens: ~25k --- nix/hpkgs.nix | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/nix/hpkgs.nix b/nix/hpkgs.nix index 2b64da0..001bee7 100644 --- a/nix/hpkgs.nix +++ b/nix/hpkgs.nix @@ -1,13 +1,30 @@ { pkgs ? import ./pkgs.nix { } , }: +let + # Decision: use lib.fileset.toSource for fine grained source filtering. + # Alternatives considered: passing ../. directly (rebuilds on any nix/tooling + # change), cleanSource (still includes too much). fileset.unions makes the + # build inputs explicit so editing nix/, .github/, makefile, .hlint.yaml, + # etc. does not invalidate the haskell build cache. + src = pkgs.lib.fileset.toSource { + root = ../.; + fileset = pkgs.lib.fileset.unions [ + ../app + ../src + ../test + ../template.cabal + ../LICENSE + ../Readme.md + ../Changelog.md + ]; + }; +in # you can pin a specific ghc version with # pkgs.haskell.packages.ghc984 for example. # this allows you to create multiple compiler targets via nix. pkgs.haskellPackages.override { overrides = hnew: hold: { - # NB this is a bit silly because nix files are now considered for the build - # bigger projects should consider putting haskell stuff in a subfolder - template-project = hnew.callCabal2nix "template-project" ../. { }; + template-project = hnew.callCabal2nix "template-project" src { }; }; }