From 59cb038045568c2cfb9d9f8e70b77d636d258158 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 31 May 2021 23:04:08 +0200 Subject: [PATCH] flake: add pre-commit-hooks Instead of havin the tool manage versions, use a pinned version. --- .pre-commit-config.yaml | 21 --------------------- flake.lock | 27 ++++++++++++++++++++++++++- flake.nix | 26 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 22 deletions(-) delete mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 0543253..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -repos: -- repo: 'https://github.com/pre-commit/pre-commit-hooks' - rev: 'v2.3.0' - hooks: - - id: 'trailing-whitespace' - - id: 'end-of-file-fixer' - - id: 'check-yaml' - - id: 'check-added-large-files' -- repo: 'https://github.com/jumanjihouse/pre-commit-hooks' - rev: '2.1.4' - hooks: - - id: 'forbid-binary' -- repo: 'local' - hooks: - - id: 'nixpkgs-fmt' - name: 'nixpkgs-fmt' - description: 'Format nix code with nixpkgs-fmt' - entry: 'nixpkgs-fmt' - language: 'system' - files: '\.nix$' - always_run: true diff --git a/flake.lock b/flake.lock index 23dd0be..29aabff 100644 --- a/flake.lock +++ b/flake.lock @@ -69,12 +69,37 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "futils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1621411868, + "narHash": "sha256-R+7OQ2JYFCb3E7Jl7LhRifzMVCR6Gl8R98zYsNhZtJ8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "2e7fac06108b4fc81f5ff9ed9a02bc4f6ede7001", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "master", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "futils": "futils", "home-manager": "home-manager", "nixpkgs": "nixpkgs", - "nur": "nur" + "nur": "nur", + "pre-commit-hooks": "pre-commit-hooks" } } }, diff --git a/flake.nix b/flake.nix index 3ff11ba..b11dbed 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,17 @@ repo = "NUR"; ref = "master"; }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "futils"; + nixpkgs.follows = "nixpkgs"; + }; + }; }; outputs = @@ -40,6 +51,7 @@ , home-manager , nixpkgs , nur + , pre-commit-hooks }: let inherit (futils.lib) eachDefaultSystem; @@ -96,6 +108,18 @@ diff-flake = futils.lib.mkApp { drv = packages.diff-flake; }; }; + checks = { + pre-commit = pre-commit-hooks.lib.${system}.run { + src = ./.; + + hooks = { + nixpkgs-fmt = { + enable = true; + }; + }; + }; + }; + defaultApp = apps.diff-flake; devShell = pkgs.mkShell { @@ -107,6 +131,8 @@ gnupg nixpkgs-fmt ]; + + inherit (self.checks.${system}.pre-commit) shellHook; }; packages = import ./pkgs { inherit pkgs; };