106 lines
3.6 KiB
Nix
106 lines
3.6 KiB
Nix
{
|
|
description = "srid/haskell-template: Nix template for Haskell projects";
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
|
systems.url = "github:nix-systems/default";
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
haskell-flake.url = "github:srid/haskell-flake";
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
|
flake-root.url = "github:srid/flake-root";
|
|
mission-control.url = "github:Platonic-Systems/mission-control";
|
|
};
|
|
|
|
outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
|
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
|
systems = import inputs.systems;
|
|
imports = [
|
|
inputs.haskell-flake.flakeModule
|
|
inputs.treefmt-nix.flakeModule
|
|
inputs.flake-root.flakeModule
|
|
inputs.mission-control.flakeModule
|
|
];
|
|
perSystem = { self', system, lib, config, pkgs, ... }: {
|
|
# Our only Haskell project. You can have multiple projects, but this template
|
|
# has only one.
|
|
# See https://github.com/srid/haskell-flake/blob/master/example/flake.nix
|
|
haskellProjects.default = {
|
|
# packages.haskell-template.root = ./.; # Auto-discovered by haskell-flake
|
|
overrides = self: super: { };
|
|
devShell = {
|
|
tools = hp: {
|
|
treefmt = config.treefmt.build.wrapper;
|
|
} // config.treefmt.build.programs;
|
|
hlsCheck.enable = true;
|
|
};
|
|
autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell
|
|
};
|
|
|
|
# Auto formatters. This also adds a flake check to ensure that the
|
|
# source tree was auto formatted.
|
|
treefmt.config = {
|
|
inherit (config.flake-root) projectRootFile;
|
|
package = pkgs.treefmt;
|
|
flakeFormatter = false; # For https://github.com/numtide/treefmt-nix/issues/55
|
|
|
|
programs.ormolu.enable = true;
|
|
programs.nixpkgs-fmt.enable = true;
|
|
programs.cabal-fmt.enable = true;
|
|
programs.hlint.enable = true;
|
|
|
|
# We use fourmolu
|
|
programs.ormolu.package = pkgs.haskellPackages.fourmolu;
|
|
settings.formatter.ormolu = {
|
|
options = [
|
|
"--ghc-opt"
|
|
"-XImportQualifiedPost"
|
|
];
|
|
};
|
|
};
|
|
|
|
# Dev shell scripts.
|
|
mission-control.scripts = {
|
|
docs = {
|
|
description = "Start Hoogle server for project dependencies";
|
|
exec = ''
|
|
echo http://127.0.0.1:8888
|
|
hoogle serve -p 8888 --local
|
|
'';
|
|
category = "Dev Tools";
|
|
};
|
|
repl = {
|
|
description = "Start the cabal repl";
|
|
exec = ''
|
|
cabal repl "$@"
|
|
'';
|
|
category = "Dev Tools";
|
|
};
|
|
fmt = {
|
|
description = "Format the source tree";
|
|
exec = config.treefmt.build.wrapper;
|
|
category = "Dev Tools";
|
|
};
|
|
run = {
|
|
description = "Run the project with ghcid auto-recompile";
|
|
exec = ''
|
|
ghcid -c "cabal repl exe:haskell-template" --warnings -T :main
|
|
'';
|
|
category = "Primary";
|
|
};
|
|
};
|
|
|
|
# Default package & app.
|
|
packages.default = self'.packages.haskell-template;
|
|
packages.app = self'.apps.haskell-template;
|
|
|
|
# Default shell.
|
|
devShells.default = pkgs.mkShell {
|
|
inputsFrom = [
|
|
config.haskellProjects.default.outputs.devShell
|
|
config.flake-root.devShell
|
|
config.mission-control.devShell
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|