I’m a new beginner to Haskell and I want to do Haskell development on NixOS. After some learning and researching, I finally settled on the existing Haskell infrastructure in Nixpkgs. So I managed to make this flake template that helps develop, package, and deliver a Haskell software.
I hope this can help you get started on a new Haskell project more conveniently and provide a reference for others who are new to Nix or Haskell. Although many techniques used in this template are trivial to you, I’d like to share my efforts and achievements just for fun. ![]()
This template includes the following basic functionalities, thanks to the brilliant Nix and Nixpkgs:
- GHC and prebuilt artifacts of dependencies
- Development shell with Haskell language server, hlint, hoogle, ghcid, etc.
- Cabal-install as development build tool and Nix as production build tool
I also try to add more functionalities to make development experience better:
- Discover Haskell packages automatically, as long as they are put in the
hs-packagesdirectory. - Support both IFD via
callCabal2nixand pre-generatedpackage.nixusingcabal2nix. The latter is preferred if exists. - Convenient
justrecipes for runninghpackandcabal2nix. - Separate dev flake partition, based on
flake-parts.flakeModules.partitions, in case that new development flake inputs are added, which won’t pollute this flake’s end users’ flake.lock.
Any suggestions are welcomed. I will be very appreciated of your feedback!