From 42df395424be66da89bf2f0876077b21376278ad Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 20 Jul 2021 20:25:51 +0200 Subject: [PATCH] flake: add pre-commit-hooks --- flake.lock | 27 ++++++++++++++++++++++++++- flake.nix | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 35cccbd..efff0aa 100644 --- a/flake.lock +++ b/flake.lock @@ -32,10 +32,35 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "futils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1624971177, + "narHash": "sha256-Amf/nBj1E77RmbSSmV+hg6YOpR+rddCbbVgo5C7BS0I=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "397f0713d007250a2c7a745e555fa16c5dc8cadb", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "master", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "futils": "futils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } } }, diff --git a/flake.nix b/flake.nix index c607956..10916bd 100644 --- a/flake.nix +++ b/flake.nix @@ -15,10 +15,21 @@ repo = "nixpkgs"; ref = "nixpkgs-unstable"; }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "futils"; + nixpkgs.follows = "nixpkgs"; + }; + }; }; - outputs = { self, nixpkgs, futils } @ inputs: - futils.lib.eachSystem futils.lib.allSystems (system: + outputs = { self, futils, nixpkgs, pre-commit-hooks } @ inputs: + futils.lib.eachDefaultSystem (system: let inherit (nixpkgs) lib; pkgs = nixpkgs.legacyPackages.${system}; @@ -37,9 +48,36 @@ ]; in { + checks = { + pre-commit = pre-commit-hooks.lib.${system}.run { + src = ./.; + + hooks = { + nixpkgs-fmt = { + enable = true; + }; + + markdown-lint = { + enable = true; + + name = "Lint each post's markdown"; + + entry = + let + pkg = pkgs.nodePackages.markdownlint-cli; + in + "${pkg}/bin/markdownlint"; + + types = [ "markdown" ]; + }; + }; + }; + }; + devShell = pkgs.mkShell { name = "report"; inherit buildInputs; + inherit (self.checks.${system}.pre-commit) shellHook; }; defaultPackage = pkgs.stdenvNoCC.mkDerivation {