Skip to content

Commit d064882

Browse files
committed
Add nix pre-commit hooks and clean up a few other things
1 parent 7baf7bd commit d064882

File tree

11 files changed

+214
-149
lines changed

11 files changed

+214
-149
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# Automatically reload when this file changes
55
watch_file nix/devshell.nix
6+
watch_file nix/checks/pre-commit.nix
67

78
# Load `nix develop`
89
use flake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,4 @@ strykeforce.sql.gz
196196
/image_renditions
197197
.nixos-test-history
198198
.envrc.local
199+
.pre-commit-config.yaml

.pre-commit-config.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

flake.lock

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
nixos-generators.url = "github:nix-community/nixos-generators";
1515
nixos-generators.inputs.nixpkgs.follows = "nixpkgs";
1616

17+
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
18+
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
19+
1720
pyproject-nix.url = "github:nix-community/pyproject.nix";
1821
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
1922

nix/checks/pre-commit.nix

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
flake,
3+
inputs,
4+
pkgs,
5+
system,
6+
...
7+
}:
8+
inputs.pre-commit-hooks.lib.${system}.run {
9+
src = ../../.;
10+
hooks =
11+
let
12+
pythonSet = flake.lib.pythonSets pkgs;
13+
venv = pythonSet.mkVirtualEnv "pre-commit-env" {
14+
website = [ "pre-commit" ];
15+
};
16+
in
17+
{
18+
nixfmt-rfc-style.enable = true;
19+
ruff.enable = true;
20+
ruff-format.enable = true;
21+
ruff-format.after = [ "ruff" ];
22+
trim-trailing-whitespace.enable = true;
23+
end-of-file-fixer.enable = true;
24+
check-yaml.enable = true;
25+
check-added-large-files.enable = true;
26+
check-added-large-files.args = [ "--maxkb=25" ];
27+
check-case-conflicts.enable = true;
28+
check-json.enable = true;
29+
check-toml.enable = true;
30+
check-merge-conflicts.enable = true;
31+
check-symlinks.enable = true;
32+
pyupgrade.enable = true;
33+
pyupgrade.args = [ "--py312-plus" ];
34+
add-trailing-comma = {
35+
enable = true;
36+
name = "add-trailing-comma";
37+
description = "Automatically add trailing commas to calls and literals.";
38+
entry = "${venv}/bin/add-trailing-comma";
39+
types = [ "python" ];
40+
};
41+
djade = {
42+
enable = true;
43+
name = "djade";
44+
description = "A Django template formatter.";
45+
entry = "${venv}/bin/djade";
46+
types = [ "html" ];
47+
};
48+
django-upgrade = {
49+
enable = true;
50+
name = "django-upgrade";
51+
description = "Automatically upgrade your Django project code.";
52+
entry = "${venv}/bin/django-upgrade --target-version=5.2";
53+
types = [ "python" ];
54+
};
55+
};
56+
}

nix/devshell.nix

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
{
22
flake,
3+
inputs,
34
perSystem,
45
pkgs,
6+
system,
57
}:
8+
let
9+
pythonSet = flake.lib.pythonSets pkgs;
10+
inherit (inputs.self.checks.${system}) pre-commit;
11+
in
612
pkgs.mkShell {
7-
packages = with pkgs; [
8-
(flake.lib.python pkgs)
9-
cachix
10-
just
11-
nil
12-
nix-output-monitor
13-
nixfmt-rfc-style
14-
nodejs
15-
postgresql.dev
16-
pre-commit
17-
tailwindcss
18-
perSystem.uv2nix.uv-bin
19-
perSystem.agenix.agenix
20-
watchman
21-
];
13+
packages =
14+
with pkgs;
15+
[
16+
pythonSet.python
17+
cachix
18+
just
19+
nil
20+
nix-output-monitor
21+
nixfmt-rfc-style
22+
nodejs
23+
postgresql.dev
24+
pre-commit
25+
tailwindcss
26+
perSystem.uv2nix.uv-bin
27+
perSystem.agenix.agenix
28+
watchman
29+
]
30+
++ pre-commit.enabledPackages;
2231

2332
env = {
2433
UV_PYTHON_DOWNLOADS = "never";
2534
};
2635

2736
shellHook = ''
2837
unset PYTHONPATH
38+
${pre-commit.shellHook}
2939
'';
3040
}

nix/lib/default.nix

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ let
66
sourcePreference = "wheel";
77
};
88

9-
python = pkgs: pkgs.python312;
10-
119
pythonSets =
1210
pkgs:
1311
let
1412
baseSet = pkgs.callPackage inputs.pyproject-nix.build.packages {
15-
python = python pkgs;
13+
python = pkgs.python312;
1614
stdenv = pkgs.stdenv.override {
1715
targetPlatform = pkgs.stdenv.targetPlatform // {
1816
# allow downloading of opencv-python wheel
@@ -24,9 +22,6 @@ let
2422
pillowHeifOverrides = import ./overrides/overrides-pillow-heif.nix { inherit pkgs; };
2523
psycopgOverrides = import ./overrides/overrides-psycopg.nix { inherit pkgs; };
2624
opencvOverrides = import ./overrides/overrides-opencv.nix { inherit pkgs; };
27-
strykeforceOverrides = import ./overrides/overrides-strykeforce.nix {
28-
inherit flake pkgs workspace;
29-
};
3025
tbaApiOverrides = import ./overrides/overrides-tba-api-v3client.nix { inherit pkgs; };
3126
in
3227
baseSet.overrideScope (
@@ -36,7 +31,6 @@ let
3631
pillowHeifOverrides
3732
psycopgOverrides
3833
opencvOverrides
39-
strykeforceOverrides
4034
tbaApiOverrides
4135
]
4236
);
@@ -45,7 +39,6 @@ in
4539

4640
inherit
4741
overlay
48-
python
4942
pythonSets
5043
workspace
5144
;

nix/lib/overrides/overrides-strykeforce.nix

Lines changed: 0 additions & 93 deletions
This file was deleted.

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ dev = [
2828
"ipython>=8.31.0",
2929
"rich>=13.9.4",
3030
]
31+
pre-commit = [
32+
"add-trailing-comma>=3.1.0",
33+
"djade>=1.3.2",
34+
"django-upgrade>=1.23.1",
35+
]
3136

3237
[build-system]
3338
requires = ["hatchling"]

0 commit comments

Comments
 (0)