Command line
pedantix formats each file in place. With no files — or a single - —
it reads from stdin and writes the formatted result to stdout.
Usage
$ pedantix [OPTIONS] [FILES]...
Arguments
| Argument | Description |
|---|---|
[FILES]... | Files to format in place. With no files (or -), reads stdin and writes the result to stdout |
Options
| Option | Description |
|---|---|
-c, --config <CONFIG> | Path to a config file (default: search for pedantix.toml or .pedantix.toml upwards from each file's directory, stopping at the git repository root — or immediately when there is no repository — then fall back to $XDG_CONFIG_HOME/pedantix/pedantix.toml) |
--config-toml <TOML> | Complete configuration as an inline TOML document; disables config file loading and discovery. Example: --config-toml 'formatter = "off"' |
--set <KEY.PATH=VALUE> | Set a single configuration value on top of the loaded config, using the same keys as pedantix.toml. Repeatable. Values are parsed as TOML. Examples: --set lets.sort=true --set 'args.first=["self"]' |
--allow-formatter-command | Execute a formatter-command found in an auto-discovered config file. Without this flag, only configs you name explicitly (--config, --config-toml, --set, the global XDG config) may specify a command to run; discovered pedantix.toml files are limited to the built-in formatter choices |
--check | Don't write anything; exit 1 if any file would be reformatted |
--formatter <FORMATTER> | Override the configured base formatter Possible values: nixfmt, alejandra, nixpkgs-fmt, off. |
--stdin-filepath <STDIN_FILEPATH> | Path the stdin content notionally comes from; used for config discovery in stdin mode |
Config discovery
When you don't pass --config or --config-toml, pedantix searches for apedantix.toml or .pedantix.toml in the same directory and searching up, stopping at the repo root (or immediately, if not in one). Otherwise it falls back to $XDG_CONFIG_HOME/pedantix/pedantix.toml.
In stdin mode, --stdin-filepath tells pedantix which directory to start that search from — this is how editor integrations get the same config a plain file run would.
formatter-command security
A config that specifies a formatter-command (an arbitrary stdin → stdout program) is only allowed to run when passed --config, --config-toml, --set via the CLI, or through the global XDG config. An auto-discovered pedantix.toml will not run an arbitrary command unless passed --allow-formatter-command.
Exit codes
| Code | Meaning |
|---|---|
0 | Success — files were formatted, or nothing needed reformatting when using --check. |
1 | With --check: at least one file would be reformatted. |
2 | Bad configuration, unreadable file, parse failure, etc. |
Examples
# Format two files in place
$ pedantix flake.nix hosts/foo.nix
# Check if any file is unformatted
$ pedantix --check $(git ls-files '*.nix')
# Additionally sort let bindings for one run
$ pedantix --set lets.sort=true file.nix
# Explicitly specify base formatter for one run
$ pedantix --formatter alejandra file.nix