From 02ce64158f185dab5806859d9279ae87bae5bfd4 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 2 Aug 2024 18:53:11 +0300 Subject: [PATCH] feat: pre commit hooks --- .gitignore | 1 + flake.lock | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--- flake.nix | 28 ++++++++++++++++++---- 3 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e90b739 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index 01ce9b4..12d1e6f 100644 --- a/flake.lock +++ b/flake.lock @@ -24,6 +24,22 @@ } }, "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-compat_2": { "locked": { "lastModified": 1696426674, "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", @@ -116,13 +132,38 @@ } }, "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs-unstable" + ], + "nixpkgs-stable": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721042469, + "narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "f451c19376071a90d8c58ab1a953c6e9840527fd", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "git-hooks_2": { "inputs": { "flake-compat": [ "nvim-flake", "nixvim", "flake-compat" ], - "gitignore": "gitignore", + "gitignore": "gitignore_2", "nixpkgs": [ "nvim-flake", "nixvim", @@ -149,6 +190,27 @@ } }, "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" + } + }, + "gitignore_2": { "inputs": { "nixpkgs": [ "nvim-flake", @@ -313,9 +375,9 @@ "nixvim": { "inputs": { "devshell": "devshell", - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_2", "flake-parts": "flake-parts_3", - "git-hooks": "git-hooks", + "git-hooks": "git-hooks_2", "home-manager": "home-manager_2", "nix-darwin": "nix-darwin", "nixpkgs": [ @@ -363,6 +425,7 @@ "root": { "inputs": { "flake-parts": "flake-parts", + "git-hooks": "git-hooks", "home-manager": "home-manager", "impermanence": "impermanence", "nixos-hardware": "nixos-hardware", diff --git a/flake.nix b/flake.nix index 4da1794..ca0abfb 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,11 @@ url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; + git-hooks = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs-unstable"; + inputs.nixpkgs-stable.follows = "nixpkgs"; + }; # Core impermanence.url = "github:nix-community/impermanence"; @@ -31,7 +36,7 @@ }; }; - outputs = inputs: + outputs = inputs @ {self, ...}: inputs.flake-parts.lib.mkFlake {inherit inputs;} { imports = [ ./systems @@ -43,11 +48,24 @@ system, ... }: { + checks.pre-commit-check = inputs.git-hooks.lib.${system}.run { + src = ./.; + hooks = { + alejandra = { + enable = true; + always_run = true; + }; + }; + }; + devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - alejandra - sops - ]; + inherit (self.checks.${system}.pre-commit-check) shellHook; + buildInputs = with pkgs; + [ + alejandra + sops + ] + ++ self.checks.${system}.pre-commit-check.enabledPackages; }; }; }; -- 2.44.1