A `flake-parts` module for Haskell development

Some of you are probably already aware of flake-parts which is a framework to “modularize” an otherwise gigantic flake.nix. It is particularly useful in monorepos.

I’d like to announce GitHub - srid/haskell-flake: A `flake-parts` Nix module for Haskell development - which provides a flake-parts module for Haskell development.

GitHub - srid/haskell-template: Haskell project template using Nix + Flakes + VSCode (HLS) already uses it.


Using haskell-flake, your flake.nix becomes as simple as:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs.follows = "nixpkgs";
    haskell-flake.url = "github:srid/haskell-flake";
  };

  outputs = { self, nixpkgs, flake-parts, haskell-flake, ... }:
    flake-parts.lib.mkFlake { inherit self; } {
      systems = nixpkgs.lib.systems.flakeExposed;
      imports = [
        haskell-flake.flakeModule
      ];
      perSystem = { self', pkgs, ... }: {
        haskellProjects.default = {
          root = ./.;
          buildTools = hp: {
            inherit (hp)
              cabal-fmt
              fourmolu;
          };
        };
      };
    };
}

Other options, like source-overrides, overrides and modifier can be specified. The main feature haskell-flake is missing is support for multiple packages, and this is something that would be a great first contribution for others to make!

2 Likes