Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
language: haskell
types:
- nix
description: The official (but not yet stable) formatter for Nix code
description: The official formatter for Nix code
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# Revision history for nixfmt

## Unreleased
## 1.0.0 -- 2025-07-09

* Parsing fixes
* Quotes in inherit statements (like `inherit "or";`) are now supported.
The [Nix Formatting Team](https://nixos.org/community/teams/formatting/) is happy to present the first stable release of the official Nix formatter! The basis for this milestone is [RFC 166](https://github.com/NixOS/rfcs/pull/166), which defined the [standard for Nix formatting](https://github.com/NixOS/nixfmt/blob/master/standard.md), established the Nix Formatting team and set the groundwork for nixfmt to become the official formatter.

Given that, this release is _significantly_ different from the previous one:
- How Nix is formatted _completely_ changed and is unrecognisable from previous versions, fixing many issues with the old formatting in the process. It would be pointless to try to list all the differences, just think of it as an entirely new formatting.
- This project graduated from a [Serokell](https://serokell.io/) project to an official Nix project, with a [repository under the NixOS org](https://github.com/nixos/nixfmt) and a community-based Nix formatting team as maintainers.

Other than the above, there are some notable UX changes:
- Deprecate `nixfmt [dir]` for recursively formatting a directory again. Please use the new `pkgs.nixfmt-tree` wrapper instead, or <https://github.com/numtide/treefmt-nix> for more flexibility, see [the docs](https://github.com/nixos/nixfmt?tab=readme-ov-file#in-a-project) for more options.
- More complete [usage documentation](https://github.com/nixos/nixfmt?tab=readme-ov-file#installation).
- A [Git mergetool mode](https://github.com/nixos/nixfmt?tab=readme-ov-file#git-mergetool) is now supported.
- CLI changes:
- In stdin-mode, `--filename <path>` can now be used to specify a filename for diagnostics.
- Number of indendation spaces can now be configured using `--indent <number>`

## 0.6.0 -- 2023-10-31

Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ When contributing, please try to familiarize yourself with the [Nix Format Stand

You can also reach us on Matrix at `#nix-formatting:nixos.org`.

## Development

Enter a development shell with `nix-shell`, `nix develop` or automatically with [direnv](https://direnv.net/), after which you can:
- Build (& run): `cabal build` (`cabal run`)
- Debug: `cabal repl`
- Format the codebase: `treefmt`
- [Set up](https://haskell-language-server.readthedocs.io/en/latest/configuration.html#configuring-your-editor) your LSP-editor to use `haskell-language-server`

To run (almost) all CI checks locally:
```
nix-build -A ci
```

## Contributing code

Most changes to the format are going to be implemented in `Pretty.hs`.
Expand Down
9 changes: 4 additions & 5 deletions MAINTENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ rather than the version from the cabalfile.

## Making a new release

- Check the commit log if anything is missing from the change log.
- Check dependency versions in `nixfmt.cabal`, bump upper bounds if possible.
- Bump the version.
- Give it a git tag.
- Upload to hackage using `cabal sdist`. See https://hackage.haskell.org/upload for details.
- Bump the version in the [cabal file](./nixfmt.cabal)
- Update the [changelog](./CHANGELOG.md) with the new version
- Create a PR with the above changes and merge it
- Create a [new GitHub release](https://github.com/NixOS/nixfmt/releases/new) with tag matching the version and set the release notes to this versions changelog
50 changes: 6 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# `nixfmt`

`nixfmt` is the official formatter for Nix language code, intended to easily apply a uniform style.

![Build Status](https://github.com/NixOS/nixfmt/actions/workflows/main.yml/badge.svg?branch=master)

## State

`nixfmt` was originally developed by [Serokell](https://github.com/serokell).
It was used as the basis for the official standardised Nix formatter, as established by [RFC 166](https://github.com/NixOS/rfcs/pull/166).

The official standard differs considerably from the original implementation.
Be aware of this if you track the [`master`](https://github.com/NixOS/nixfmt/tree/master) branch.
Until the [next release](https://github.com/NixOS/nixfmt/issues/272), expect `nixfmt` to change.
# Nixfmt

A recent version of `nixfmt` is available as `pkgs.nixfmt-rfc-style` in Nixpkgs.
The original `nixfmt` is still available as `pkgs.nixfmt-classic`, but it is unmaintained and will eventually be removed.

For more details, see the [RFC implementation tracking issue](https://github.com/NixOS/nixfmt/issues/153).
Nixfmt is the official formatter for Nix language code.
It is maintained by the [Nix formatting team](https://nixos.org/community/teams/formatting/).
This document is the user documentation, see [CONTRIBUTING.md](./CONTRIBUTING.md) for contributor documentation.

## Installation

Expand Down Expand Up @@ -229,9 +217,6 @@ includes = ["*.nix"]

6. Try to commit a badly formatted Nix file in order to make sure that everything works.

> [!WARNING]
> `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.

#### `git mergetool`

`nixfmt` provides a mode usable by [`git mergetool`](https://git-scm.com/docs/git-mergetool)
Expand Down Expand Up @@ -304,34 +289,11 @@ to return back to the unmerged state.
}
```

## Development

### With Nix

Haskell dependencies will be built by Nix.

* Enter `nix-shell`
* Build with `cabal new-build`

### Without Nix

Haskell dependencies will be built by Cabal.

* Build with `cabal new-build`


## Usage

* `nixfmt < input.nix` – reads Nix code from `stdin`, formats it, and outputs to `stdout`
* `nixfmt file.nix` – format the file in place

## About Serokell

`nixfmt` is maintained and funded with :heart: by
[Serokell](https://serokell.io/). The names and logo for Serokell are trademark
of Serokell OÜ.
## Acknowledgements

We love open source software! See
[our other projects](https://serokell.io/community?utm_source=github) or
[hire us](https://serokell.io/hire-us?utm_source=github) to design, develop and
grow your idea!
`nixfmt` was originally developed by [Serokell](https://github.com/serokell) and later donated to become an official Nix project with the acceptance of [RFC 166](https://github.com/NixOS/rfcs/pull/166).
4 changes: 2 additions & 2 deletions nixfmt.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 2.0
name: nixfmt
version: 0.6.0
synopsis: Official formatter for Nix code
version: 1.0.0
synopsis: Official formatter for Nix code
description:
A formatter for Nix that ensures consistent and clear formatting by forgetting
almost all existing formatting during parsing.
Expand Down