nix: add pre-commit-hooks
Some checks failed
ci/woodpecker/pr/cargo-checks Pipeline was successful
ci/woodpecker/cron/flake-update Pipeline failed

This commit is contained in:
notohh 2024-04-08 18:45:30 -04:00
parent 926f213923
commit 200d2a86d3
Signed by: notohh
GPG key ID: BD47506D475EE86D
5 changed files with 153 additions and 5 deletions

5
.gitignore vendored
View file

@ -25,4 +25,7 @@ target/
.vscode/ .vscode/
# nix # nix
result/ result/
# pre-commit
/.pre-commit-config.yaml

View file

@ -20,6 +20,61 @@
"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": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"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": 1711703276, "lastModified": 1711703276,
@ -36,6 +91,22 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-stable": {
"locked": {
"lastModified": 1710695816,
"narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "614b4613980a522ba49f0d194531beddbb7220d3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1712543224, "lastModified": 1712543224,
@ -52,11 +123,50 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_3": {
"locked": {
"lastModified": 1710765496,
"narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_3",
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1712579741,
"narHash": "sha256-igpsH+pa6yFwYOdah3cFciCk8gw+ytniG9quf5f/q84=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "70f504012f0a132ac33e56988e1028d88a48855c",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"fenix": "fenix", "fenix": "fenix",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"systems": "systems" "pre-commit-hooks": "pre-commit-hooks",
"systems": "systems_2"
} }
}, },
"rust-analyzer-src": { "rust-analyzer-src": {
@ -77,6 +187,21 @@
} }
}, },
"systems": { "systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": { "locked": {
"lastModified": 1689347949, "lastModified": 1689347949,
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",

View file

@ -5,6 +5,7 @@
systems.url = "github:nix-systems/default-linux"; systems.url = "github:nix-systems/default-linux";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
fenix.url = "github:nix-community/fenix/monthly"; fenix.url = "github:nix-community/fenix/monthly";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
}; };
outputs = { outputs = {
@ -12,7 +13,8 @@
systems, systems,
nixpkgs, nixpkgs,
fenix, fenix,
} @ inputs: let pre-commit-hooks,
}: let
eachSystem = nixpkgs.lib.genAttrs (import systems); eachSystem = nixpkgs.lib.genAttrs (import systems);
pkgsFor = eachSystem (system: pkgsFor = eachSystem (system:
import nixpkgs { import nixpkgs {
@ -22,7 +24,7 @@
in { in {
packages = eachSystem (system: let packages = eachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version; inherit ((builtins.fromTOML (builtins.readFile ./Cargo.toml)).package) version;
in { in {
default = pkgsFor.${system}.rustPlatform.buildRustPackage { default = pkgsFor.${system}.rustPlatform.buildRustPackage {
pname = "forcebot_rs"; pname = "forcebot_rs";
@ -40,8 +42,23 @@
doCheck = false; doCheck = false;
}; };
}); });
checks = eachSystem (system: {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
# rust
rustfmt.enable = true;
clippy.enable = true;
# nix
statix.enable = true;
alejandra.enable = true;
deadnix.enable = true;
};
};
});
devShells = eachSystem (system: { devShells = eachSystem (system: {
default = pkgsFor.${system}.mkShell { default = pkgsFor.${system}.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
packages = with pkgsFor.${system}; [ packages = with pkgsFor.${system}; [
nil nil
alejandra alejandra

View file

@ -17,7 +17,7 @@ in {
package = mkOption { package = mkOption {
type = types.package; type = types.package;
default = self.packages.${system}.default; inherit (self.packages.${system}) default;
}; };
}; };

3
statix.toml Normal file
View file

@ -0,0 +1,3 @@
disabled = []
nix_version = '2.4'
ignore = ['.direnv']