This is a template for a Haskell project using Nix for development and deployment.
With nix as the single requirement and direnv as a optional one, it uses for environment management:
- direnv to automatically enter the development environment.
- nix to manage dependencies and build the project.
- devenv to manage the development environment.
- treefmt to format all project files in the directory structure.
For Haskell development, it uses:
- ghc as the compiler.
- cabal to build the project.
- ghcid to run a development server.
- hlint to lint the code.
- fourmolu to format the code.
- haskell-language-server to provide language server protocol support for your favorite editor.
.
├── app # Executable source code
│ └── Main.hs
├── src # Core source code
│ └── Hello
│ └── Haskell.hs
├── tests # Test source code
│ ├── Hello
│ │ └── HaskellSpec.hs
│ └── Spec.hs # Utilize hspec-discover to discover all tests ending with Spec.hs and exporting spec :: Spec
├── cabal.project
├── flake.nix # Nix flake with devenv, packages, checks and apps
├── fourmolu.yaml # Fourmolu configuration
├── myhaskell.cabal # Cabal file
├── myhaskell.nix # Nix file the haskell project
└── treefmt.nix # Formatting tools for the whole project
With direnv installed, run direnv allow
to set up the environment or run nix develop
to
enter development shell manually.
Run ghcid, continuous compilation and testing of the code:
devenv up dev
Using cabal:
cabal repl myhaskell:exe:myhaskell
cabal build myhaskell
Run compiled module via flake:
$ nix run
Hello, Haskell!
Format all files:
treefmt