This repository uses treefmt with nixfmt and deadnix to maintain consistent formatting and clean code in Nix files.
-
Purpose: Formats Nix code according to RFC 166 style guidelines
-
What it does:
- Standardizes indentation and spacing
- Formats function calls and attribute sets consistently
- Ensures consistent line breaks and alignment
-
Purpose: Removes unused/dead code from Nix expressions
-
What it does:
- Identifies unused variables and bindings
- Removes unused function arguments
- Cleans up dead code paths
# Run treefmt and format all Nix files in the repository
nix fmtThe formatter is available when you enter the development shell:
# Enter development shell
nix develop
# Format all nix files
treefmt
# Format specific files
treefmt file1.nix file2.nix
# Check formatting without making changes
treefmt --check
# Format with verbose output
treefmt --verboseIf you're using direnv, the formatter is automatically available:
cd /path/to/project
treefmtThe formatter configuration is defined with nix in nix/fmt.nix using treefmt-nix.
See the treefmt-nix project documentation
for the list of supported formatters and their configurations.
The formatter is automatically run via pre-commit hooks (see pre-commit-hooks.md) to ensure all committed code is properly formatted.
nix fmt
git add .
git commit -m "your message"Sometimes we want to first review formatting changes to ensure they're sensible:
# See what would be changed
treefmt --check --diffUse the Nix IDE extension with treefmt support.