Skip to content

Commit 3d18524

Browse files
committed
Move pre-commit instructions up
1 parent 5443fe5 commit 3d18524

File tree

1 file changed

+45
-46
lines changed

1 file changed

+45
-46
lines changed

README.md

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ So installing this `nixfmt` is as simple as adding to the system packages:
3838
It's also possible to install `nixfmt` directly from the repository using `nix-env`.
3939
Also, updates are not done automatically (as it would with the system packages).
4040

41-
```
42-
nix-env -f https://github.com/NixOS/nixfmt/archive/master.tar.gz -i
41+
```console
42+
$ nix-env -f https://github.com/NixOS/nixfmt/archive/master.tar.gz -i
4343
```
4444

4545
### nix fmt
@@ -99,6 +99,49 @@ More information about configuration can be found in [the README](https://github
9999
}
100100
```
101101

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+
102145
### neovim + nixd
103146

104147
```lua
@@ -167,50 +210,6 @@ Haskell dependencies will be built by Cabal.
167210
* `nixfmt < input.nix` – reads Nix code from `stdin`, formats it, and outputs to `stdout`
168211
* `nixfmt file.nix` – format the file in place
169212

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.
212-
213-
214213
## About Serokell
215214

216215
`nixfmt` is maintained and funded with :heart: by

0 commit comments

Comments
 (0)