For those who want to jump into the code: Add `haskell.lib.incremental` utility by Gabriella439 · Pull Request #204020 · NixOS/nixpkgs · GitHub.
I hope we can generalize it, because nixpkgs#167670 adds similar functionality, but perhaps less adapted to haskell?