From 2140bf39e41767f25a395d20fb0d5698b8934b33 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 12 Feb 2025 20:28:12 +0100 Subject: [PATCH] CONTRIBUTING: Improve and update formatting docs --- CONTRIBUTING.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f14915b6b50..d4a573f5bb3c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -531,14 +531,31 @@ If you removed packages or made some major NixOS changes, write about it in the Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be `all-packages.nix`, not `allPackages.nix` or `AllPackages.nix`. +### Formatting + +CI [enforces](./.github/workflows/check-nix-format.yml) all Nix files to be +formatted using the [official Nix formatter](https://github.com/NixOS/nixfmt). + +You can ensure this locally using either of these commands: +``` +nix-shell --run treefmt +nix develop --command treefmt +nix fmt +``` + +If you're starting your editor in `nix-shell` or `nix develop`, +you can also set it up to automatically format the file with `treefmt` on save. + +If you have any problems with formatting, please ping the +[formatting team](https://nixos.org/community/teams/formatting/) via +[@NixOS/nix-formatting](https://github.com/orgs/NixOS/teams/nix-formatting). + ### Syntax - Set up [editorconfig](https://editorconfig.org/) for your editor, such that [the settings](./.editorconfig) are automatically applied. - Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [package naming](./pkgs/README.md#package-naming). -- New files must be formatted by entering the `nix-shell` from the repository root and running `nixfmt`. - - Functions should list their expected arguments as precisely as possible. That is, write ```nix