Skip to content

Latest commit

 

History

History
73 lines (55 loc) · 2.14 KB

README.md

File metadata and controls

73 lines (55 loc) · 2.14 KB

Haskell Nix Template

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:

Directory Structure

.
├── 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

Usage

With direnv installed, run direnv allow to set up the environment or run nix develop to enter development shell manually.

Development

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