diff --git a/.gitignore b/.gitignore index 1015ac96..99bae731 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ dist /assets/tailwind.css -/.vscode/spellright.dict \ No newline at end of file +/.vscode/spellright.dict + +/.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index f5f6593c..29a8a8e3 100644 --- a/flake.lock +++ b/flake.lock @@ -81,6 +81,22 @@ "type": "github" } }, + "git-hooks": { + "flake": false, + "locked": { + "lastModified": 1737465171, + "narHash": "sha256-R10v2hoJRLq8jcL4syVFag7nIGE7m13qO48wRIukWNg=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "inspect": { "flake": false, "locked": { @@ -180,6 +196,7 @@ "devour-flake": "devour-flake", "false": "false", "flake-parts": "flake-parts", + "git-hooks": "git-hooks", "inspect": "inspect", "nix-systems-aarch64-darwin": "nix-systems-aarch64-darwin", "nix-systems-aarch64-linux": "nix-systems-aarch64-linux", @@ -188,7 +205,6 @@ "nixpkgs": "nixpkgs", "rust-flake": "rust-flake", "systems": "systems", - "treefmt-nix": "treefmt-nix", "true": "true" } }, @@ -250,26 +266,6 @@ "type": "github" } }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1724338379, - "narHash": "sha256-kKJtaiU5Ou+e/0Qs7SICXF22DLx4V/WhG1P6+k4yeOE=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "070f834771efa715f3e74cd8ab93ecc96fabc951", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - }, "true": { "locked": { "lastModified": 1657739253, diff --git a/flake.nix b/flake.nix index 74ee2be4..ff7f6a94 100644 --- a/flake.nix +++ b/flake.nix @@ -11,8 +11,8 @@ rust-flake.url = "github:juspay/rust-flake"; rust-flake.inputs.nixpkgs.follows = "nixpkgs"; - treefmt-nix.url = "github:numtide/treefmt-nix"; - treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + git-hooks.url = "github:cachix/git-hooks.nix"; + git-hooks.flake = false; cachix-push.url = "github:juspay/cachix-push"; # We cache these inputs locally, and then have Omnix reference the catched inputs. diff --git a/justfile b/justfile index 900403f9..88dd761f 100644 --- a/justfile +++ b/justfile @@ -4,11 +4,9 @@ mod doc default: @just --list -# Auto-format the source tree -fmt: - treefmt - -alias f := fmt +# Run all pre-commit hooks on all files +pca: + pre-commit run -a # Run omnix-cli locally watch *ARGS: diff --git a/nix/modules/flake-parts/devshell.nix b/nix/modules/flake-parts/devshell.nix index 032e88c0..2d0d6528 100644 --- a/nix/modules/flake-parts/devshell.nix +++ b/nix/modules/flake-parts/devshell.nix @@ -11,7 +11,7 @@ in name = "omnix-devshell"; meta.description = "Omnix development environment"; inputsFrom = [ - config.treefmt.build.devShell + config.pre-commit.devShell self'.devShells.rust ]; inherit (config.rust-project.crates."omnix-cli".crane.args) diff --git a/nix/modules/flake-parts/formating.nix b/nix/modules/flake-parts/formating.nix deleted file mode 100644 index 6cb36336..00000000 --- a/nix/modules/flake-parts/formating.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ inputs, ... }: -{ - imports = [ - inputs.treefmt-nix.flakeModule - ]; - - perSystem = { - # Add your auto-formatters here. - # cf. https://nixos.asia/en/treefmt - treefmt.config = { - projectRootFile = "flake.nix"; - programs = { - nixpkgs-fmt.enable = true; - rustfmt.enable = true; - }; - }; - }; -} diff --git a/nix/modules/flake-parts/pre-commit.nix b/nix/modules/flake-parts/pre-commit.nix new file mode 100644 index 00000000..a1f580d5 --- /dev/null +++ b/nix/modules/flake-parts/pre-commit.nix @@ -0,0 +1,15 @@ +{ inputs, ... }: +{ + imports = [ + (inputs.git-hooks + /flake-module.nix) + ]; + + perSystem = { + pre-commit.settings = { + hooks = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + }; + }; + }; +}