3
3
HS_FILES = $(shell git ls-files '* .hs' '* .hs-boot' | grep -v '^contrib/')
4
4
CHANGED_HS_FILES = $(shell git diff --diff-filter=d --name-only `git merge-base HEAD origin/main` | grep '.* \(\.hs\|hs-boot\) $$' | grep -v '^contrib/')
5
5
6
+ NIX_FILES = $(shell git ls-files '* .nix' 'nix/* .nix')
7
+
6
8
SHELL_FILES = $(shell git ls-files '* .sh')
7
9
CHANGED_SHELL_FILES = $(shell git diff --diff-filter=d --name-only `git merge-base HEAD origin/main` | grep '.* \.sh$$')
8
10
9
11
HLINT = hlint
10
12
13
+ NIX_FMT = nixpkgs-fmt
14
+
11
15
ORMOLU_CHECK_VERSION = 0.3.0.0
12
16
ORMOLU_ARGS = --cabal-default-extensions
13
17
ORMOLU = ormolu
@@ -56,17 +60,39 @@ check-format-hs-changed: check-ormolu-version
56
60
$(ORMOLU ) $(ORMOLU_ARGS ) --mode check $(CHANGED_HS_FILES ) ; \
57
61
fi
58
62
63
+ # We don't bother checking only changed *.nix files, as there's so few.
64
+
65
+ .PHONY : format-nix
66
+ # # format-nix: auto-format Nix source code using `nixpkgs-fmt`
67
+ format-nix :
68
+ @if command -v $(NIX_FMT ) > /dev/null; then \
69
+ echo " running $( NIX_FMT) " ; \
70
+ $(NIX_FMT ) $(NIX_FILES ) ; \
71
+ else \
72
+ echo " $( NIX_FMT) is not installed; skipping" ; \
73
+ fi
74
+
75
+ .PHONY : check-format-nix
76
+ # # check-format-nix: check Nix source code using `nixpkgs-fmt`
77
+ check-format-nix :
78
+ @if command -v $(NIX_FMT ) > /dev/null; then \
79
+ echo " running $( NIX_FMT) --check" ; \
80
+ $(NIX_FMT ) --check $(NIX_FILES ) ; \
81
+ else \
82
+ echo " $( NIX_FMT) is not installed; skipping" ; \
83
+ fi
84
+
59
85
.PHONY : format
60
- format : format-hs
86
+ format : format-hs format-nix
61
87
62
88
.PHONY : format-changed
63
- format-changed : format-hs-changed
89
+ format-changed : format-hs-changed format-nix
64
90
65
91
.PHONY : check-format
66
- check-format : check-format-hs
92
+ check-format : check-format-hs check-format-nix
67
93
68
94
.PHONY : check-format-changed
69
- check-format-changed : check-format-hs-changed
95
+ check-format-changed : check-format-hs-changed check-format-nix
70
96
71
97
.PHONY : lint-hs
72
98
# # lint-hs: lint Haskell code using `hlint`
@@ -83,13 +109,13 @@ lint-hs-changed:
83
109
fi
84
110
85
111
.PHONY : lint-shell
86
- # # lint-shell: lint shell scripts using `shellcheck`
112
+ # # lint-shell: lint shell scripts using `shellcheck`
87
113
lint-shell :
88
114
@echo running shellcheck
89
115
@$(SHELLCHECK ) $(SHELL_FILES )
90
116
91
117
.PHONY : lint-shell-changed
92
- # # lint-shell-changed: lint shell scripts using `shellcheck` (changed files only)
118
+ # # lint-shell-changed: lint shell scripts using `shellcheck` (changed files only)
93
119
lint-shell-changed :
94
120
@echo running shellcheck
95
121
@if [ -n " $( CHANGED_SHELL_FILES) " ]; then \
0 commit comments