From b1a5e16432e4d1cc661d0aa7e7aa6da28d3028fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Mon, 11 Nov 2024 17:39:20 +0100 Subject: [PATCH] Add pre-commit hooks for formatting and dead code --- .gitignore | 1 + flake.lock | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 12 +++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3276413..81bd15e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ result* output todo +/.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index b614c58..4221865 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,64 @@ "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" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1730814269, + "narHash": "sha256-fWPHyhYE6xvMI1eGY3pwBTq85wcy1YXqdzTZF+06nOg=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "d70155fdc00df4628446352fc58adc640cd705c2", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-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": { "locked": { "lastModified": 1725194671, @@ -49,7 +107,39 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1730741070, + "narHash": "sha256-edm8WG19kWozJ/GqyYx2VjW99EdhjKwbY3ZwdlPAAlo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d063c1dd113c91ab27959ba540c0d9753409edf3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { + "locked": { + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1730137230, "narHash": "sha256-0kW6v0alzWIc/Dc/DoVZ7A9qNScv77bj/zYTKI67HZM=", @@ -85,7 +175,8 @@ "root": { "inputs": { "disko": "disko", - "nixpkgs": "nixpkgs_2", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs_3", "nixpkgs-latest": "nixpkgs-latest", "pixelfed": "pixelfed" } diff --git a/flake.nix b/flake.nix index 67f7cf4..7836171 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,8 @@ inputs = { nixpkgs.url = "github:radvendii/nixpkgs/nixos_rebuild_tests"; nixpkgs-latest.url = "github:nixos/nixpkgs"; + git-hooks.url = "github:cachix/git-hooks.nix"; + pixelfed = { url = "github:pixelfed/pixelfed?ref=v0.12.3"; flake = false; @@ -14,6 +16,7 @@ self, nixpkgs, nixpkgs-latest, + git-hooks, pixelfed, disko, }: @@ -120,12 +123,21 @@ checks.${system} = { mastodon-garage = import ./tests/mastodon-garage.nix { inherit pkgs self; }; pixelfed-garage = import ./tests/pixelfed-garage.nix { inherit pkgs self; }; + + pre-commit = git-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixfmt-rfc-style.enable = true; + deadnix.enable = true; + }; + }; }; devShells.${system}.default = pkgs.mkShell { inputs = with pkgs; [ nil ]; + shellHook = self.checks.${system}.pre-commit.shellHook; }; }; }