diff --git a/README.md b/README.md index 4e4d40b..4ee40e8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ For details, see: https://srid.ca/haskell-template/start - Run `nix flake update` to update all flake inputs. - Run `nix --option sandbox false build .#check -L` to run the flake checks. -- Run `, fmt` in nix shell to autoformat the project. This uses [treefmt](https://github.com/numtide/treefmt), which uses `./treefmt.toml` (where fourmolu and nixpkgs-fmt are specified). +- Run `, fmt` in nix shell to autoformat the project. This uses [treefmt](https://github.com/numtide/treefmt). - Run `, docs` to start Hoogle with packages in your cabal file. - Run the application without installing: `nix run github:srid/haskell-template` (or `nix run .` from checkout) - Common workflows diff --git a/flake.lock b/flake.lock index 1a975f8..21cdf2b 100644 --- a/flake.lock +++ b/flake.lock @@ -123,21 +123,22 @@ "haskell-flake": "haskell-flake", "mission-control": "mission-control", "nixpkgs": "nixpkgs_2", - "treefmt-flake": "treefmt-flake" + "treefmt-nix": "treefmt-nix" } }, - "treefmt-flake": { + "treefmt-nix": { "locked": { - "lastModified": 1669929251, - "narHash": "sha256-+qgCD89JyZhBNF4m/HuuVrpoRoXMTl5F60mJzr3QPNM=", - "owner": "srid", - "repo": "treefmt-flake", - "rev": "86341cd4a0ce21556a348fd27a4797997d27be00", + "lastModified": 1671645275, + "narHash": "sha256-aHpd0f/WBO4a3kK7wy8tsp4iGTOGEAY3sL/ujOLkqw0=", + "owner": "Platonic-Systems", + "repo": "treefmt-nix", + "rev": "8280dec5403061434de195b81854d65e6613b5ca", "type": "github" }, "original": { - "owner": "srid", - "repo": "treefmt-flake", + "owner": "Platonic-Systems", + "ref": "flake-module", + "repo": "treefmt-nix", "type": "github" } } diff --git a/flake.nix b/flake.nix index 06fe4f3..de2b02c 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; haskell-flake.url = "github:srid/haskell-flake"; - treefmt-flake.url = "github:srid/treefmt-flake"; + treefmt-nix.url = "github:Platonic-Systems/treefmt-nix/flake-module"; # https://github.com/numtide/treefmt-nix/pull/14 flake-root.url = "github:srid/flake-root"; mission-control.url = "github:Platonic-Systems/mission-control"; }; @@ -14,7 +14,7 @@ systems = nixpkgs.lib.systems.flakeExposed; imports = [ inputs.haskell-flake.flakeModule - inputs.treefmt-flake.flakeModule + inputs.treefmt-nix.flakeModule inputs.flake-root.flakeModule inputs.mission-control.flakeModule ]; @@ -25,7 +25,9 @@ packages = { haskell-template.root = ./.; }; - buildTools = hp: { } // config.treefmt.formatters; + buildTools = hp: { + treefmt = config.treefmt.wrapper; + } // config.treefmt.programs; # overrides = self: super: {} hlsCheck.enable = true; hlintCheck.enable = true; @@ -33,12 +35,22 @@ # Auto formatters. This also adds a flake check to ensure that the # source tree was auto formatted. - treefmt.formatters = { - inherit (pkgs) - nixpkgs-fmt; - inherit (pkgs.haskellPackages) - cabal-fmt - fourmolu; + treefmt.config = { + package = pkgs.treefmt; + projectRootFile = "flake.nix"; + + programs.ormolu.enable = true; + programs.ormolu.package = pkgs.haskellPackages.fourmolu; + settings.formatter.ormolu = { + options = [ + "--ghc-opt" + "-XImportQualifiedPost" + ]; + }; + + programs.nixpkgs-fmt.enable = true; + + programs.cabal-fmt.enable = true; }; # Dev shell scripts. @@ -60,7 +72,7 @@ }; fmt = { description = "Format the source tree"; - exec = "${lib.getExe pkgs.treefmt}"; + exec = "${lib.getExe config.treefmt.wrapper}"; category = "Dev Tools "; }; run = { diff --git a/treefmt.toml b/treefmt.toml deleted file mode 100644 index 08b1a0b..0000000 --- a/treefmt.toml +++ /dev/null @@ -1,21 +0,0 @@ -[formatter.haskell] -command = "fourmolu" -options = [ - "--ghc-opt", - "-XImportQualifiedPost", - "--ghc-opt", - "-XTypeApplications", - "--mode", - "inplace", - "--check-idempotence", -] -includes = ["*.hs"] - -[formatter.nix] -command = "nixpkgs-fmt" -includes = ["*.nix"] - -[formatter.cabal] -command = "cabal-fmt" -options = ["--inplace"] -includes = ["*.cabal"]