lix/src/nix/fmt.md
2022-03-11 10:00:19 -05:00

1 KiB

R""(

Examples

With nixpkgs-fmt:

# flake.nix
{
  outputs = { nixpkgs, self }: {
    formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
  };
}
  • Format the current flake: $ nix fmt

  • Format a specific folder or file: $ nix fmt ./folder ./file.nix

With nixfmt:

# flake.nix
{
  outputs = { nixpkgs, self }: {
    formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt;
  };
}
  • Format specific files: $ nix fmt ./file1.nix ./file2.nix

With Alejandra:

# flake.nix
{
  outputs = { nixpkgs, self }: {
    formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.alejandra;
  };
}
  • Format the current flake: $ nix fmt

  • Format a specific folder or file: $ nix fmt ./folder ./file.nix

Description

nix fmt will rewrite all Nix files (*.nix) to a canonical format using the formatter specified in your flake.

)""