treefmt

pedantix integrates with treefmt-nix as a formatter program.

With flake-parts

Import the flake module and enable the program under perSystem:

{
  imports = [
    inputs.treefmt-nix.flakeModule
    inputs.pedantix.flakeModules.default
  ];
  perSystem = _: {
    treefmt.programs.pedantix = {
      enable = true;
    };
  };
}

Without flake-parts

Use the standalone treefmt module with treefmt-nix's evalModule:

let
  treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs {
    imports = [ inputs.pedantix.treefmtModules.default ];
    projectRootFile = "flake.nix";
    programs.pedantix.enable = true;
  };
in
{
  formatter.${system} = treefmtEval.config.build.wrapper;
  checks.${system}.formatting = treefmtEval.config.build.check self;
}

Options

settings is translated into --set key=value flags, so each key is merged on top of any pedantix.toml discovered in the project. This yields one quirk: setting overrides in settings replaces a discovered overrides list, whereas preset-provided overrides still combine. If you want to keep a project's pedantix.toml authoritative, prefer configFile (or rely on discovery) over restating everything in settings.

programs.pedantix.enable

Whether to enable pedantix, the pedantic Nix formatter.

Type: boolean

Default:

false

Example:

true

programs.pedantix.package

The pedantix package to run. The default wrapper ships nixfmt, alejandra and nixpkgs-fmt on PATH; use the unwrapped pedantix package if you provide the base formatter yourself.

Type: package

Default:

pedantix.packages.${system}.pedantix-wrapped

programs.pedantix.configFile

A complete pedantix.toml to use instead of config file discovery (settings still applies on top).

Type: null or absolute path

Default:

null

programs.pedantix.excludes

Path / file patterns to exclude.

Type: list of string

Default:

[ ]

Example:

[
  "generated/*.nix"
]

programs.pedantix.extraArgs

Extra command line arguments passed to pedantix, appended after the flags generated from settings and configFile.

Type: list of string

Default:

[ ]

Example:

[
  "--formatter=nixpkgs-fmt"
]

programs.pedantix.includes

Path / file patterns to include.

Type: list of string

Default:

[
  "*.nix"
]

programs.pedantix.priority

treefmt priority, for ordering relative to other formatters on the same files.

Type: null or signed integer

Default:

null

programs.pedantix.settings

pedantix configuration, using the same structure as pedantix.toml.

Passed as --set flags, i.e. each key is merged on top of any pedantix.toml discovered in the project (overrides replaces a discovered override list; preset overrides still combine).

Type: attribute set of anything

Default:

{ }

Example:

{
  preset = "nixos-module";
  formatter = "alejandra";
  args.first = [ "self" "lib" "config" "pkgs" ];
  lets.sort = true;
  overrides = [
    {
      path = "**.programs.git.settings.alias";
      attrs.sort = false;
    }
  ];
}

Full example

treefmt.programs.pedantix = {
  enable = true;
  settings = {
    preset = "nixos-module";
    formatter = "alejandra";
    lets.sort = true;
    overrides = [
      {
        path = "**.programs.git.settings.alias";
        attrs.sort = false;
      }
    ];
  };
};