Configuration
pedantix is configured with a TOML file (see config discovery).
Individual values can also be passed on the command line with --set, e.g. pedantix --set lets.sort=true file.nix, or the whole document inline with --config-toml.
preset
This applies a base layer of configuration which you can layer your own config atop of - see Presets.
preset = "nixos-module"
Reference
Top-level keys
| Key | Type | Default | Description |
|---|---|---|---|
format-after-sort | bool | true | Run the base formatter again after sorting. |
format-before-sort | bool | true | Run the base formatter before sorting. |
formatter | FormatterChoice | "nixfmt" | Base formatter run before and after sorting. |
formatter-command | list of string | — | Arbitrary stdin -> stdout command; overrides formatter. Because it runs an external program, it is only honored from configs named explicitly (--config, --config-toml, --set, the global XDG config); an auto-discovered config requires --allow-formatter-command. |
inherit-placement | InheritPlacement | "front" | Where inherit statements land relative to ordinary bindings. |
top-level-blank-lines | int | — | Exact number of blank lines between the bindings of the file's outermost attribute set. Unset keeps existing blank lines as-is. |
top-level-blank-lines-depth | int | 1 | How deep the top-level spacing reaches: 1 is only the outermost set, 2 also covers the sets its bindings define, and so on. In flake.nix, inputs and outputs always count as top-level sets. |
top-level-blank-lines-mode | BlankLinesMode | "multiline" | Which top-level bindings receive the blank-line spacing. |
Construct rules ([args], [attrs], [lets], [inherits], [lists])
The
merge,flatten, andblank-lines*keys only apply to[attrs].
| Key | Type | Default | Description |
|---|---|---|---|
blank-lines | int | — | (attrs only) Number of blank lines between the set's bindings. Unset keeps the existing spacing. |
blank-lines-depth | int | 1 | (attrs only) How deep the spacing reaches; wrappers such as functions and lets do not count as levels. |
blank-lines-mode | BlankLinesMode | — | (attrs only) Which bindings receive the blank-line spacing. |
first | list of string | [] | Names pinned to the front, in the given order. The sentinel "<defaulted>" stands for all arguments with a default value (name ? value); "..." is the ellipsis. |
flatten | bool | false | (attrs only) Flatten a binding whose value is an attrset holding a single binding into one attrpath: a = { b = 1; }; becomes a.b = 1;. Overrides match the path of the set being flattened. |
last | list of string | [] | Names pinned to the end, in the given order. |
merge | bool | false | (attrs only) Merge bindings sharing their first attrpath component into one nested set: a.b = 1; a.c = 2; becomes a = { b = 1; c = 2; };. |
sort | bool | true | Whether to reorder this construct at all. |
Override keys ([[overrides]])
| Key | Type | Default | Description |
|---|---|---|---|
args | partial rules | — | Function-argument rules to apply to matched paths. |
attrs | partial rules | — | Attribute-set rules to apply to matched paths. |
inherits | partial rules | — | inherit rules to apply to matched paths. |
lets | partial rules | — | let-binding rules to apply to matched paths. |
lists | partial rules | — | List-element rules to apply to matched paths. |
path | string | — | Glob over dot-separated attribute paths. * matches exactly one component, ** any number (including zero). |
FormatterChoice values
| Value | Description |
|---|---|
"nixfmt" | |
"alejandra" | |
"nixpkgs-fmt" | |
"off" | Disable the base formatter; only reorder. |
BlankLinesMode values
| Value | Description |
|---|---|
"multiline" | Space bindings whose text spans several lines; keep consecutive single-line bindings together. |
"all" | Apply spacing to all bindings. |
"off" | Suppress spacing entirely. |
InheritPlacement values
| Value | Description |
|---|---|
"front" | Pin `inherit lines to the top of the set. |
"last" | Pin `inherit lines to the bottom of the set. |
"sorted" | Sort `inherit lines alphabetically among the bindings. |
Notes
The five construct tables share one shape
[args], [attrs], [lets], [inherits], and [lists] all take the same sort rules keys. Names not listed in first / last are sorted alphabetically between them. The merge, flatten, and blank-lines* keys are only meaningful under [attrs].
[args]
first = ["self", "lib", "config", "pkgs"]
last = ["<defaulted>", "..."]
[attrs]
first = ["imports", "enable", "package"]
[lets]
sort = true
[lets], [inherits], and [lists] are off by default. List sorting in particular is best enabled per-path via an override rather than globally, since list order is often significant.
merge shared attribute paths
[attrs]
merge = true
turns a.b = 1; a.c = 2; into a = { b = 1; c = 2; };. This does not fix broken evaluation by e.g. dynamically derived attribute set names.
flatten single-binding attribute sets
[attrs]
flatten = true
turns a = { b = 1; }; into a.b = 1;, provided b is the only binding in the set. This skips on rec, inherit, dynamic keys, and comments around binding.
Top-level blank lines vs. [attrs] blank-lines
The top-level-blank-lines* keys and the [attrs] blank-lines* keys look similar but do slightly different things:
top-level-blank-linesdoes not descend into function-call sets, and treats aflake.nixinputs/outputsbody as its own top-level set.
[attrs] blank-linesapplies to every attrset the[attrs]rules match, at any nesting depth (including sets inside function calls), and can be targeted per path via[[overrides]].
A reordered set by default drops all blank lines, so set one of these to restore spacing.
[inherits] vs. inherit-placement
[inherits] sorts the names inside an inherit. The top-level inherit-placement key is separate: it controls where the whole inherit statement sits relative to other bindings.
Per-path overrides
The [[overrides]] array lets you change any of the rules above for specific attribute paths — see Overrides.