From 105fdc89ac4fd6892c14e8dc57b3d9eee666544d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 3 Jan 2025 13:24:11 -0500 Subject: [PATCH] nix: treefmt -> git-hooks.nix --- .gitignore | 3 ++- flake.lock | 40 ++++++++++++++++++---------------------- flake.nix | 32 +++++++++++++++----------------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 54ffe60..ab2b6a9 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ cabal.project.local~ result result-* -.direnv \ No newline at end of file +.direnv +/.pre-commit-config.yaml \ No newline at end of file diff --git a/flake.lock b/flake.lock index 102858e..ef1aee9 100644 --- a/flake.lock +++ b/flake.lock @@ -243,6 +243,22 @@ "type": "github" } }, + "git-hooks": { + "flake": false, + "locked": { + "lastModified": 1735882644, + "narHash": "sha256-3FZAG+pGt3OElQjesCAWeMkQ7C/nB1oTHLRQ8ceP110=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "haskell-flake": { "locked": { "lastModified": 1709233214, @@ -420,11 +436,11 @@ "ema": "ema", "flake-parts": "flake-parts_3", "fourmolu-nix": "fourmolu-nix", + "git-hooks": "git-hooks", "haskell-flake": "haskell-flake_3", "nixpkgs": "nixpkgs_3", "process-compose-flake": "process-compose-flake", - "systems": "systems_2", - "treefmt-nix": "treefmt-nix_3" + "systems": "systems_2" } }, "systems": { @@ -497,26 +513,6 @@ "type": "github" } }, - "treefmt-nix_3": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1735905407, - "narHash": "sha256-1hKMRIT+QZNWX46e4gIovoQ7H8QRb7803ZH4qSKI45o=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "29806abab803e498df96d82dd6f34b32eb8dd2c8", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - }, "unionmount": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index b16f906..43b0cad 100644 --- a/flake.nix +++ b/flake.nix @@ -7,9 +7,9 @@ haskell-flake.url = "github:srid/haskell-flake"; process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; - treefmt-nix.url = "github:numtide/treefmt-nix"; - treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; fourmolu-nix.url = "github:jedimahdi/fourmolu-nix"; + git-hooks.url = "github:cachix/git-hooks.nix"; + git-hooks.flake = false; ema.url = "github:srid/ema"; ema.inputs.nixpkgs.follows = "nixpkgs"; @@ -20,10 +20,10 @@ imports = [ inputs.haskell-flake.flakeModule inputs.process-compose-flake.flakeModule - inputs.treefmt-nix.flakeModule inputs.fourmolu-nix.flakeModule + (inputs.git-hooks + /flake-module.nix) ]; - perSystem = { config, self', pkgs, lib, ... }: + perSystem = { config, pkgs, lib, ... }: let tailwind = pkgs.haskellPackages.tailwind; in @@ -36,18 +36,16 @@ autoWire = [ "packages" "apps" "checks" ]; }; - # 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; - programs.nixpkgs-fmt.enable = true; - programs.cabal-fmt.enable = true; - programs.hlint.enable = true; - - # We use fourmolu - programs.fourmolu.package = config.fourmolu.wrapper; + pre-commit.settings = { + hooks = { + nixpkgs-fmt.enable = true; + cabal-fmt.enable = true; + fourmolu = { + enable = true; + package = config.fourmolu.wrapper; + }; + hlint.enable = true; + }; }; fourmolu.settings = { @@ -105,7 +103,7 @@ ]; inputsFrom = [ config.haskellProjects.default.outputs.devShell - config.treefmt.build.devShell + config.pre-commit.devShell ]; }; };