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

@ -31,6 +31,22 @@
"type": "github" "type": "github"
} }
}, },
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
@ -49,6 +65,27 @@
"type": "github" "type": "github"
} }
}, },
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1747958103, "lastModified": 1747958103,
@ -65,12 +102,35 @@
"type": "github" "type": "github"
} }
}, },
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1747372754,
"narHash": "sha256-2Y53NGIX2vxfie1rOW0Qb86vjRZ7ngizoo+bnXU9D9k=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "80479b6ec16fefd9c1db3ea13aeb038c60530f46",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"advisory-db": "advisory-db", "advisory-db": "advisory-db",
"crane": "crane", "crane": "crane",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
} }
}, },

View file

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