From 3a2af5fb697cdff717a92217aad99252ce6acef1 Mon Sep 17 00:00:00 2001 From: Jurn Wubben Date: Sat, 24 May 2025 14:34:52 +0200 Subject: [PATCH] Added git hooks --- .gitignore | 2 ++ flake.lock | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- flake.nix | 18 +++++++++++++-- 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 92b2793..7cc31c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .direnv +.pre-commit-config.yaml + diff --git a/flake.lock b/flake.lock index 1a2ff62..f1b8f0f 100644 --- a/flake.lock +++ b/flake.lock @@ -145,6 +145,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": 1733328505, "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", @@ -158,7 +174,7 @@ "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" } }, - "flake-compat_2": { + "flake-compat_3": { "locked": { "lastModified": 1733328505, "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", @@ -328,7 +344,7 @@ "stylix", "flake-compat" ], - "gitignore": "gitignore", + "gitignore": "gitignore_2", "nixpkgs": [ "stylix", "nixpkgs" @@ -348,7 +364,50 @@ "type": "github" } }, + "git-hooks-nix": { + "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" + } + }, "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks-nix", + "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": [ "stylix", @@ -549,7 +608,7 @@ }, "nixcord": { "inputs": { - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_2", "nixpkgs": "nixpkgs_3", "systems": "systems_3", "treefmt-nix": "treefmt-nix" @@ -776,6 +835,7 @@ "agenix": "agenix", "dcbot": "dcbot", "flake-parts": "flake-parts", + "git-hooks-nix": "git-hooks-nix", "guiders": "guiders", "hm": "hm", "nixcord": "nixcord", @@ -835,7 +895,7 @@ "base16-helix": "base16-helix", "base16-vim": "base16-vim", "firefox-gnome-theme": "firefox-gnome-theme", - "flake-compat": "flake-compat_2", + "flake-compat": "flake-compat_3", "flake-utils": "flake-utils_4", "git-hooks": "git-hooks", "gnome-shell": "gnome-shell", diff --git a/flake.nix b/flake.nix index 3a42442..6b3243b 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ inputs.flake-parts.lib.mkFlake {inherit inputs;} { systems = ["x86_64-linux"]; imports = [ + inputs.git-hooks-nix.flakeModule ./hosts ]; @@ -13,6 +14,13 @@ pkgs, ... }: { + pre-commit.settings.hooks = { + alejandra.enable = true; + flake-checker.enable = true; + nil.enable = true; + }; + + formatter = pkgs.alejandra; devShells.default = pkgs.mkShell { packages = [ pkgs.alejandra @@ -20,9 +28,11 @@ ]; name = "dots"; DIRENV_LOG_FORMAT = ""; - }; - formatter = pkgs.alejandra; + shellHook = '' + ${config.pre-commit.installationScript} + ''; + }; }; }; @@ -31,6 +41,10 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # build error unrelated to config. nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.11-small"; # build error unrelated to config. flake-parts.url = "github:hercules-ci/flake-parts"; + git-hooks-nix = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; hm = { url = "github:nix-community/home-manager/master";