Here are some gists that demonstrate how to wrap a Haskell project with Nix, without changing the Haskell.
A handful of cases are covered:
- simple package
- package with custom Setup and external helper programs
- a repository/project containing multiple packages
For the most part, you just have to copy the .nix files into your project and add the .gitignore content.
If you need a how-to, these should also serve as a minimal example you can imitate for any of the more complex cases.
(I’m not 100% certain that the monorepo ones shouldn’t be configured somehow to pull in all the same .gitignore content that git itself would, e.g. system and user files, instead of just the local one and having to put e.g. backup syntax or other stuff in there that would normally go at the system level.)
There are a couple interesting issues uncovered here, though, that you should be able to use these as minimal complete reproductions for.
- Cabal v1-build with –enable-nix is broken at the moment.
- Cabal build (v2) with external helper programs (the custom Setup cases) can’t find the nix-shell-provided executables.
- At least a year ago when I first started ( NixOS/nixpkgs#176887 ), nix-build was not as strict as cabal v1-build with regard to some dependencies: “…[cabal v1-build] is stricter about putting imported modules in the custom-setup setup-depends (I have to add process to import System.Process – good, I should figure out if I can get Nix builds to be this strict).”
Here’s the list: