Skip to content

Commit 719f76a

Browse files
committed
feat(flakeModules): Add git-hook module and dogfood it
1 parent e8e0809 commit 719f76a

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ matrix-*.json
1313
shardMatrix.json
1414

1515
.vscode
16+
17+
# Pre Commit
18+
.pre-commit-config.yaml

checks/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
{
33
imports = [
44
./packages-ci-matrix.nix
5+
./pre-commit.nix
56
];
67
}

checks/pre-commit.nix

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{ inputs, ... }:
2+
{
3+
flake.flakeModules.git-hooks =
4+
{ config, ... }:
5+
{
6+
imports = [
7+
# Import git-hooks flake-parts module
8+
# docs: https://flake.parts/options/git-hooks-nix
9+
inputs.git-hooks-nix.flakeModule
10+
];
11+
12+
config = {
13+
perSystem =
14+
{ ... }:
15+
{
16+
devShells.pre-commit =
17+
let
18+
inherit (config.pre-commit.settings) enabledPackages package;
19+
in
20+
pkgs.mkShell {
21+
packages = enabledPackages ++ [ package ];
22+
shellHook = ''
23+
echo "Running Pre-commit checks"
24+
echo "========================="
25+
'';
26+
};
27+
28+
# impl: https://github.com/cachix/git-hooks.nix/blob/master/flake-module.nix
29+
pre-commit = {
30+
# Disable `checks` flake output
31+
check.enable = false;
32+
33+
# Enable commonly used formatters
34+
settings.hooks = {
35+
# Basic whitespace formatting
36+
editorconfig-checker.enable = true;
37+
38+
# *.nix formatting
39+
nixfmt-rfc-style.enable = true;
40+
41+
# *.rs formatting
42+
rustfmt.enable = true;
43+
44+
# *.{js,jsx,ts,tsx,css,html,md,json} formatting
45+
prettier = {
46+
enable = true;
47+
args = [
48+
"--check"
49+
"--list-different=false"
50+
"--log-level=warn"
51+
"--ignore-unknown"
52+
"--write"
53+
];
54+
};
55+
};
56+
};
57+
};
58+
};
59+
};
60+
}

shells/default.nix

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
{ ... }:
1+
{ inputs, ... }:
22
{
3+
imports = [
4+
(import ../checks/pre-commit.nix {
5+
inherit inputs;
6+
}).flake.flakeModules.git-hooks
7+
];
8+
39
perSystem =
410
{
511
pkgs,
612
inputs',
13+
config,
714
...
815
}:
916
{
@@ -36,10 +43,12 @@
3643
inputs'.dlang-nix.packages.dmd
3744
];
3845

39-
shellHook = ''
40-
export REPO_ROOT="$PWD"
41-
figlet -t "Metacraft Nixos Modules"
42-
'';
46+
shellHook =
47+
''
48+
export REPO_ROOT="$PWD"
49+
figlet -t "Metacraft Nixos Modules"
50+
''
51+
+ config.pre-commit.installationScript;
4352
};
4453
};
4554
}

0 commit comments

Comments
 (0)