aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-03-08 09:50:39 -0800
committerJohn MacFarlane <[email protected]>2023-03-08 11:15:17 -0800
commitc879fed90c17f084f897e08c7052c9ff72ff9d6a (patch)
tree75d394c9aa38795c5e518a231804f6a2f658b07a /flake.nix
parent1643225cdda2ed706f30cb76f536baa2de135ebc (diff)
Add flake.nix.
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix101
1 files changed, 101 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 000000000..ea7f4c08b
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,101 @@
+{
+ description = "srid/haskell-template: Nix template for Haskell projects";
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
+ 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";
+
+ nixpkgs-140774-workaround.url = "github:srid/nixpkgs-140774-workaround";
+ };
+
+ outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
+ flake-parts.lib.mkFlake { inherit inputs; } {
+ systems = nixpkgs.lib.systems.flakeExposed;
+ imports = [
+ inputs.haskell-flake.flakeModule
+ inputs.treefmt-nix.flakeModule
+ inputs.flake-root.flakeModule
+ inputs.mission-control.flakeModule
+ ];
+ perSystem = { self', system, lib, config, pkgs, ... }: {
+ # The "main" project. You can have multiple projects, but this template
+ # has only one.
+ haskellProjects.main = {
+ imports = [
+ inputs.nixpkgs-140774-workaround.haskellFlakeProjectModules.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;
+ };
+ };
+
+ # 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;
+
+ 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 = "${lib.getExe 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.
+ packages.default = self'.packages.main-haskell-template;
+
+ # Default shell.
+ devShells.default =
+ config.mission-control.installToDevShell self'.devShells.main;
+ };
+ };
+}