diff --git a/flake.nix b/flake.nix index f4584b3..57e54b1 100644 --- a/flake.nix +++ b/flake.nix @@ -13,107 +13,22 @@ outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { systems = import inputs.systems; - imports = [ - inputs.haskell-flake.flakeModule - inputs.treefmt-nix.flakeModule - inputs.fourmolu-nix.flakeModule - ]; - # TODO: Remove this. Only relevant for github:srid/haskell-template - flake.templates.default = { - description = "A batteries-included Haskell project template for Nix"; - path = builtins.path { path = inputs.self; }; - }; + # See ./nix/modules/*.nix for the modules that are imported here. + imports = + with builtins; map + (fn: ./nix/modules/${fn}) + (attrNames (readDir ./nix/modules)); perSystem = { self', 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 = { - # To avoid unnecessary rebuilds, we filter projectRoot: - # https://community.flake.parts/haskell-flake/local#rebuild - projectRoot = builtins.toString (lib.fileset.toSource { - root = ./.; - fileset = lib.fileset.unions [ - ./src - ./haskell-template.cabal - ./LICENSE - ./README.md - ]; - }); - - # The base package set (this value is the default) - # basePackages = pkgs.haskellPackages; - - # Packages to add on top of `basePackages` - packages = { - # Add source or Hackage overrides here - # (Local packages are added automatically) - /* - aeson.source = "1.5.0.0" # Hackage version - shower.source = inputs.shower; # Flake input - */ - }; - - # Add your package overrides here - settings = { - /* - haskell-template = { - haddock = false; - }; - aeson = { - check = false; - }; - */ - }; - - # Development shell configuration - devShell = { - hlsCheck.enable = false; - }; - - # What should haskell-flake add to flake outputs? - 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 = { - projectRootFile = "flake.nix"; - - programs.fourmolu = { - enable = true; - package = config.fourmolu.wrapper; - }; - programs.nixpkgs-fmt.enable = true; - programs.cabal-fmt.enable = true; - programs.hlint.enable = true; - }; - - fourmolu.settings = { - indentation = 2; - comma-style = "leading"; - record-brace-space = true; - indent-wheres = true; - import-export-style = "diff-friendly"; - respectful = true; - haddock-style = "multi-line"; - newlines-between-decls = 1; - extensions = [ "ImportQualifiedPost" ]; - }; - - # Default package & app. - packages.default = self'.packages.haskell-template; - apps.default = self'.apps.haskell-template; - # Default shell. devShells.default = pkgs.mkShell { name = "haskell-template"; meta.description = "Haskell development environment"; # See https://community.flake.parts/haskell-flake/devshell#composing-devshells inputsFrom = [ - config.haskellProjects.default.outputs.devShell - config.treefmt.build.devShell + config.haskellProjects.default.outputs.devShell # See ./nix/modules/haskell.nix + config.treefmt.build.devShell # See ./nix/modules/formatter.nix ]; packages = with pkgs; [ just diff --git a/nix/modules/formatter.nix b/nix/modules/formatter.nix new file mode 100644 index 0000000..e8b09bc --- /dev/null +++ b/nix/modules/formatter.nix @@ -0,0 +1,29 @@ +{ + perSystem = { config, pkgs, ... }: { + # Auto formatters. This also adds a flake check to ensure that the + # source tree was auto formatted. + treefmt.config = { + projectRootFile = "flake.nix"; + + programs.fourmolu = { + enable = true; + package = config.fourmolu.wrapper; + }; + programs.nixpkgs-fmt.enable = true; + programs.cabal-fmt.enable = true; + programs.hlint.enable = true; + }; + + fourmolu.settings = { + indentation = 2; + comma-style = "leading"; + record-brace-space = true; + indent-wheres = true; + import-export-style = "diff-friendly"; + respectful = true; + haddock-style = "multi-line"; + newlines-between-decls = 1; + extensions = [ "ImportQualifiedPost" ]; + }; + }; +} diff --git a/nix/modules/haskell.nix b/nix/modules/haskell.nix new file mode 100644 index 0000000..80a81af --- /dev/null +++ b/nix/modules/haskell.nix @@ -0,0 +1,61 @@ +{ inputs, ... }: +{ + imports = [ + inputs.haskell-flake.flakeModule + ]; + perSystem = { self', 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 = { + # To avoid unnecessary rebuilds, we filter projectRoot: + # https://community.flake.parts/haskell-flake/local#rebuild + projectRoot = builtins.toString (lib.fileset.toSource { + root = ../..; + fileset = lib.fileset.unions [ + ../../src + ../../haskell-template.cabal + ../../LICENSE + ../../README.md + ]; + }); + + # The base package set (this value is the default) + # basePackages = pkgs.haskellPackages; + + # Packages to add on top of `basePackages` + packages = { + # Add source or Hackage overrides here + # (Local packages are added automatically) + /* + aeson.source = "1.5.0.0" # Hackage version + shower.source = inputs.shower; # Flake input + */ + }; + + # Add your package overrides here + settings = { + /* + haskell-template = { + haddock = false; + }; + aeson = { + check = false; + }; + */ + }; + + # Development shell configuration + devShell = { + hlsCheck.enable = false; + }; + + # What should haskell-flake add to flake outputs? + autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell + }; + + # Default package & app. + packages.default = self'.packages.haskell-template; + apps.default = self'.apps.haskell-template; + }; +} diff --git a/nix/modules/template.nix b/nix/modules/template.nix new file mode 100644 index 0000000..bc90d79 --- /dev/null +++ b/nix/modules/template.nix @@ -0,0 +1,12 @@ +{ inputs, ... }: + +{ + imports = [ + inputs.treefmt-nix.flakeModule + inputs.fourmolu-nix.flakeModule + ]; + flake.templates.default = { + description = "A batteries-included Haskell project template for Nix"; + path = builtins.path { path = inputs.self; }; + }; +}