Skip to content

Commit 1fb1bf8

Browse files
committed
flake: move formatting and git hooks into dedicated modules
1 parent 97819ce commit 1fb1bf8

File tree

3 files changed

+133
-117
lines changed

3 files changed

+133
-117
lines changed

flake/dev/default.nix

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,12 @@
1-
{ inputs, ... }:
21
{
32
imports = [
43
./devshell.nix
4+
./fmt.nix
55
./generate-all-maintainers
6+
./git-hooks.nix
67
./list-plugins
78
./package-tests.nix
89
./template-tests.nix
910
./tests.nix
10-
inputs.git-hooks.flakeModule
11-
inputs.treefmt-nix.flakeModule
1211
];
13-
14-
perSystem =
15-
{
16-
pkgs,
17-
config,
18-
system,
19-
...
20-
}:
21-
{
22-
ci.buildbot = {
23-
inherit (config.checks) treefmt;
24-
};
25-
26-
treefmt.config = {
27-
projectRootFile = "flake.nix";
28-
flakeCheck = true;
29-
30-
programs = {
31-
# keep-sorted start block=yes newline_separated=no
32-
isort.enable = true;
33-
keep-sorted.enable = true;
34-
nixfmt = {
35-
enable = true;
36-
package = pkgs.nixfmt-rfc-style;
37-
};
38-
prettier = {
39-
enable = true;
40-
excludes = [ "**.md" ];
41-
};
42-
ruff = {
43-
check = true;
44-
format = true;
45-
};
46-
shfmt.enable = true;
47-
statix = {
48-
enable = true;
49-
disabled-lints = [
50-
# We often use `nullable == true`
51-
"bool_comparison"
52-
];
53-
};
54-
stylua.enable = true;
55-
# FIXME: re-enable on darwin, currently broken: taplo with options '[format]' failed to apply: exit status 101
56-
taplo.enable = pkgs.stdenv.isLinux;
57-
# keep-sorted end
58-
};
59-
60-
settings = {
61-
global.excludes = [
62-
".editorconfig"
63-
".envrc"
64-
".git-blame-ignore-revs"
65-
".gitignore"
66-
"LICENSE"
67-
"flake.lock"
68-
"**.md"
69-
"**.scm"
70-
"**.svg"
71-
"**/man/*.5"
72-
# Those files are generated by pytest-regression, which then `diff`s them.
73-
# Formatting them will make the tests fail.
74-
"docs/gfm-alerts-to-admonitions/tests/**/*.yml"
75-
];
76-
formatter.ruff-format.options = [ "--isolated" ];
77-
};
78-
};
79-
80-
pre-commit = {
81-
# We have a treefmt check already, so this is redundant.
82-
# We also can't run the test if it includes running `nix build`,
83-
# since the nix CLI can't build within a derivation builder.
84-
check.enable = false;
85-
86-
settings.hooks = {
87-
deadnix = {
88-
enable = true;
89-
90-
settings = {
91-
noLambdaArg = true;
92-
noLambdaPatternNames = true;
93-
edit = true;
94-
};
95-
};
96-
treefmt = {
97-
enable = true;
98-
package = config.formatter;
99-
};
100-
typos = {
101-
enable = true;
102-
excludes = [ "generated/*" ];
103-
};
104-
maintainers = {
105-
enable = true;
106-
name = "maintainers";
107-
description = "Check maintainers when it is modified.";
108-
files = "^lib/maintainers[.]nix$";
109-
package = pkgs.nix;
110-
entry = "nix build --no-link --print-build-logs";
111-
args = [ ".#checks.${system}.maintainers" ];
112-
pass_filenames = false;
113-
};
114-
plugins-by-name = {
115-
enable = true;
116-
name = "plugins-by-name";
117-
description = "Check `plugins/by-name` when it's modified.";
118-
files = "^(?:tests/test-sources/)?plugins/by-name/";
119-
package = pkgs.nix;
120-
entry = "nix build --no-link --print-build-logs";
121-
args = [ ".#checks.${system}.plugins-by-name" ];
122-
pass_filenames = false;
123-
};
124-
};
125-
};
126-
};
12712
}

flake/dev/fmt.nix

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{ inputs, ... }:
2+
{
3+
imports = [
4+
inputs.treefmt-nix.flakeModule
5+
];
6+
7+
perSystem =
8+
{ config, pkgs, ... }:
9+
{
10+
ci.buildbot = {
11+
inherit (config.checks) treefmt;
12+
};
13+
14+
treefmt.config = {
15+
projectRootFile = "flake.nix";
16+
flakeCheck = true;
17+
18+
programs = {
19+
# keep-sorted start block=yes newline_separated=no
20+
isort.enable = true;
21+
keep-sorted.enable = true;
22+
nixfmt = {
23+
enable = true;
24+
package = pkgs.nixfmt-rfc-style;
25+
};
26+
prettier = {
27+
enable = true;
28+
excludes = [ "**.md" ];
29+
};
30+
ruff = {
31+
check = true;
32+
format = true;
33+
};
34+
shfmt.enable = true;
35+
statix = {
36+
enable = true;
37+
disabled-lints = [
38+
# We often use `nullable == true`
39+
"bool_comparison"
40+
];
41+
};
42+
stylua.enable = true;
43+
# FIXME: re-enable on darwin, currently broken: taplo with options '[format]' failed to apply: exit status 101
44+
taplo.enable = pkgs.stdenv.isLinux;
45+
# keep-sorted end
46+
};
47+
48+
settings = {
49+
global.excludes = [
50+
".editorconfig"
51+
".envrc"
52+
".git-blame-ignore-revs"
53+
".gitignore"
54+
"LICENSE"
55+
"flake.lock"
56+
"**.md"
57+
"**.scm"
58+
"**.svg"
59+
"**/man/*.5"
60+
# Those files are generated by pytest-regression, which then `diff`s them.
61+
# Formatting them will make the tests fail.
62+
"docs/gfm-alerts-to-admonitions/tests/**/*.yml"
63+
];
64+
formatter.ruff-format.options = [ "--isolated" ];
65+
};
66+
};
67+
68+
};
69+
}

flake/dev/git-hooks.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{ inputs, ... }:
2+
{
3+
imports = [
4+
inputs.git-hooks.flakeModule
5+
];
6+
7+
perSystem =
8+
{
9+
config,
10+
pkgs,
11+
system,
12+
...
13+
}:
14+
{
15+
pre-commit = {
16+
# We have a treefmt check already, so this is redundant.
17+
# We also can't run the test if it includes running `nix build`,
18+
# since the nix CLI can't build within a derivation builder.
19+
check.enable = false;
20+
21+
settings.hooks = {
22+
deadnix = {
23+
enable = true;
24+
25+
settings = {
26+
noLambdaArg = true;
27+
noLambdaPatternNames = true;
28+
edit = true;
29+
};
30+
};
31+
treefmt = {
32+
enable = true;
33+
package = config.formatter;
34+
};
35+
typos = {
36+
enable = true;
37+
excludes = [ "generated/*" ];
38+
};
39+
maintainers = {
40+
enable = true;
41+
name = "maintainers";
42+
description = "Check maintainers when it is modified.";
43+
files = "^lib/maintainers[.]nix$";
44+
package = pkgs.nix;
45+
entry = "nix build --no-link --print-build-logs";
46+
args = [ ".#checks.${system}.maintainers" ];
47+
pass_filenames = false;
48+
};
49+
plugins-by-name = {
50+
enable = true;
51+
name = "plugins-by-name";
52+
description = "Check `plugins/by-name` when it's modified.";
53+
files = "^(?:tests/test-sources/)?plugins/by-name/";
54+
package = pkgs.nix;
55+
entry = "nix build --no-link --print-build-logs";
56+
args = [ ".#checks.${system}.plugins-by-name" ];
57+
pass_filenames = false;
58+
};
59+
};
60+
};
61+
};
62+
}

0 commit comments

Comments
 (0)