add commit hook for rust template

This commit is contained in:
ulic-youthlic 2025-05-25 23:28:27 +08:00
parent b5cb9e511e
commit 227441f5d6
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
2 changed files with 88 additions and 0 deletions

View file

@ -17,6 +17,12 @@
crane = {
url = "github:ipetkov/crane";
};
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = {
self,
@ -25,6 +31,7 @@
rust-overlay,
advisory-db,
crane,
pre-commit-hooks,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
@ -70,6 +77,24 @@
in {
formatter = pkgs.alejandra;
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra = {
enable = true;
};
rustfmt.enable = true;
cargo-check = {
enable = true;
stages = ["pre-push"];
};
clippy = {
enable = true;
stages = ["pre-push"];
settings.denyWarnings = true;
};
};
};
package = self.packages.${system}.default.overrideAttrs {
doCheck = true;
};
@ -111,6 +136,9 @@
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
shellHook =
''''
+ self.checks.${system}.pre-commit-check.shellHook;
packages = with pkgs; [
rust-analyzer
cargo-audit