Add a shareable pre-commit hook

This commit is contained in:
2026-03-27 15:25:54 +00:00
parent cf460d529f
commit c49ad590ad
5 changed files with 180 additions and 5 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
# direnv cache
/.direnv
# "nix build" default output link
result
# nix pre-commit autogenerated by devShell
/.pre-commit-config.yaml

102
flake.lock generated Normal file
View File

@@ -0,0 +1,102 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1767039857,
"narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=",
"owner": "NixOS",
"repo": "flake-compat",
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "flake-compat",
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1774104215,
"narHash": "sha256-EAtviqz0sEAxdHS4crqu7JGR5oI3BwaqG0mw7CmXkO8=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "f799ae951fde0627157f40aec28dec27b22076d0",
"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": 1774623183,
"narHash": "sha256-Oi8z/LMdeGaBBhe1v4P3wRcwbfJjjq1hjpF5EVgnxyA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "73e3cc5c77627ac9037a197e196ae88f5b209121",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs",
"systems": "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"
}
}
},
"root": "root",
"version": 7
}

View File

@@ -1,11 +1,54 @@
{
description = "Shared Nix settings (NixOS, Home Manager etc)";
outputs = { self }: {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
systems.url = "github:nix-systems/default";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
systems,
git-hooks,
...
}:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
nixosModules = {
nix-settings = import ./modules/nix-settings.nix;
nix-gc = import ./modules/nix-gc.nix;
futureware = import ./modules/futureware.nix;
};
lib.pre-commit = import ./pre-commit.nix;
checks = eachSystem (system: {
pre-commit-check = git-hooks.lib.${system}.run {
src = ./.;
inherit (self.lib.pre-commit) hooks;
};
});
devShells = eachSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages;
in
{
default = pkgs.mkShell {
packages = enabledPackages;
inherit shellHook;
};
}
);
};
}

21
pre-commit.nix Normal file
View File

@@ -0,0 +1,21 @@
{
hooks = {
check-added-large-files.enable = true;
check-case-conflicts.enable = true;
check-executables-have-shebangs.enable = true;
check-merge-conflicts.enable = true;
check-symlinks.enable = true;
check-vcs-permalinks.enable = true;
check-yaml.enable = true;
end-of-file-fixer.enable = true;
trim-trailing-whitespace.enable = true;
ripsecrets.enable = true;
# Nix
flake-checker.enable = true;
nixfmt-rfc-style.enable = true;
deadnix.enable = true;
nil.enable = true;
statix.enable = true; # Use: statix fix
};
}