flake: add pre-commit-hooks

Instead of havin the tool manage versions, use a pinned version.
This commit is contained in:
Bruno BELANYI 2021-05-31 23:04:08 +02:00
parent 15db81eb3b
commit 59cb038045
3 changed files with 52 additions and 22 deletions

View file

@ -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

View file

@ -69,12 +69,37 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"futils": "futils", "futils": "futils",
"home-manager": "home-manager", "home-manager": "home-manager",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nur": "nur" "nur": "nur",
"pre-commit-hooks": "pre-commit-hooks"
} }
} }
}, },

View file

@ -31,6 +31,17 @@
repo = "NUR"; repo = "NUR";
ref = "master"; 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 = outputs =
@ -40,6 +51,7 @@
, home-manager , home-manager
, nixpkgs , nixpkgs
, nur , nur
, pre-commit-hooks
}: }:
let let
inherit (futils.lib) eachDefaultSystem; inherit (futils.lib) eachDefaultSystem;
@ -96,6 +108,18 @@
diff-flake = futils.lib.mkApp { drv = packages.diff-flake; }; 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; defaultApp = apps.diff-flake;
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
@ -107,6 +131,8 @@
gnupg gnupg
nixpkgs-fmt nixpkgs-fmt
]; ];
inherit (self.checks.${system}.pre-commit) shellHook;
}; };
packages = import ./pkgs { inherit pkgs; }; packages = import ./pkgs { inherit pkgs; };