My simple multi-package Haskell project template flake

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. :smiley:

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-packages directory.
  • Support both IFD via callCabal2nix and pre-generated package.nix using cabal2nix. The latter is preferred if exists.
  • Convenient just recipes for running hpack and cabal2nix.
  • 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!