You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -99,6 +99,49 @@ More information about configuration can be found in [the README](https://github
99
99
}
100
100
```
101
101
102
+
### `pre-commit` tool
103
+
104
+
If you have Nix files in a Git repo and you want to make sure that they’re formatted with `nixfmt`, then you can use the `pre-commit` tool from [pre-commit.com](https://pre-commit.com):
105
+
106
+
1. Make sure that you have the `pre-commit` command:
107
+
108
+
```console
109
+
$ pre-commit --version
110
+
pre-commit 3.7.1
111
+
```
112
+
113
+
2. Make sure that you’re in your Git repo:
114
+
115
+
```console
116
+
$ cd <path-to-git-repo>
117
+
```
118
+
119
+
3. Make sure that the `pre-commit` tool is installed as a Git pre-commit hook:
120
+
121
+
```console
122
+
$ pre-commit install
123
+
pre-commit installed at .git/hooks/pre-commit
124
+
```
125
+
126
+
4. If you don’t already have one, then create a `.pre-commit-config.yaml` file.
127
+
128
+
5. Add an entry for the `nixfmt` hook to your `.pre-commit-config.yaml` file:
129
+
130
+
```yaml
131
+
repos:
132
+
- repo: https://github.com/NixOS/nixfmt
133
+
rev: <version>
134
+
hooks:
135
+
- id: nixfmt
136
+
```
137
+
138
+
If you want to use a stable version of `nixfmt`, then replace `<version>` with a tag from this repo. If you want to use an unstable version of `nixfmt`, then replace `<version>` with a commit hash from this repo.
139
+
140
+
6. Try to commit a badly formatted Nix file in order to make sure that everything works.
141
+
142
+
> [!WARNING]
143
+
> `nixfmt`’s integration with the `pre-commit` tool is relatively new. At the moment, none of the stable releases of `nixfmt` can be used with the `pre-commit` tool. You’ll have to use an unstable version for the time being.
144
+
102
145
### neovim + nixd
103
146
104
147
```lua
@@ -167,50 +210,6 @@ Haskell dependencies will be built by Cabal.
167
210
*`nixfmt < input.nix` – reads Nix code from `stdin`, formats it, and outputs to `stdout`
168
211
*`nixfmt file.nix` – format the file in place
169
212
170
-
### With the `pre-commit` tool
171
-
172
-
If you have Nix files in a Git repo and you want to make sure that they’re formatted with `nixfmt`, then you can use the `pre-commit` tool from [pre-commit.com](https://pre-commit.com):
173
-
174
-
1. Make sure that you have the `pre-commit` command:
175
-
176
-
```console
177
-
$ pre-commit --version
178
-
pre-commit 3.7.1
179
-
```
180
-
181
-
2. Make sure that you’re in your Git repo:
182
-
183
-
```console
184
-
$ cd <path-to-git-repo>
185
-
```
186
-
187
-
3. Make sure that the `pre-commit` tool is installed as a Git pre-commit hook:
188
-
189
-
```console
190
-
$ pre-commit install
191
-
pre-commit installed at .git/hooks/pre-commit
192
-
```
193
-
194
-
4. If you don’t already have one, then create a `.pre-commit-config.yaml` file.
195
-
196
-
5. Add an entry for the `nixfmt` hook to your `.pre-commit-config.yaml` file:
197
-
198
-
```
199
-
repos:
200
-
- repo: https://github.com/NixOS/nixfmt
201
-
rev: <version>
202
-
hooks:
203
-
- id: nixfmt
204
-
```
205
-
206
-
If you want to use a stable version of `nixfmt`, then replace `<version>` with a tag from this repo. If you want to use an unstable version of `nixfmt`, then replace `<version>` with a commit hash from this repo.
207
-
208
-
6. Try to commit a badly formatted Nix file in order to make sure that everything works.
209
-
210
-
> [!WARNING]
211
-
> `nixfmt`’s integration with the `pre-commit` tool is relatively new. At the moment, none of the stable releases of `nixfmt` can be used with the `pre-commit` tool. You’ll have to use an unstable version for the time being.
0 commit comments