/alejandra

The Uncompromising Nix Code Formatter

Primary LanguageJavaScriptThe UnlicenseUnlicense

Alejandra 💅

The Uncompromising Nix Code Formatter

CI/CD Coverage License: The Unlicense style: Alejandra

Try it on your browser! here

Features

  • ✔️ Fast

    It's written in Rust and formats Nixpkgs in just a few seconds. 1

  • ✔️ Powerful

    We define a comprehensive style for all possible combinations of the Nix expression language.

  • ✔️ Reliable

    High coverage, battle tested.

    From Nix's eyes, code is just the same. 2

  • ✔️ Beautiful

    Beauty is subjective, right?

    We started from the wisdom of the crowd, which comes in big part from the 2.3 million lines of code of Nixpkgs. Then we applied the feedback of developers who have used Nix on a day to day basis for several years.

  • ✔️ Transparent

    You won't notice the formatter after a while.

    Humans care about the content, machines about the style!

  • ✔️ Native

    We integrate with common code editors:

Getting started

On the web editor

Please visit: kamadorueda.github.io/alejandra

Prebuilt binaries

You can download a binary for your platform from the releases section, make it executable and have fun!

Alternatively there is an automated method. It needs: curl, sh and chmod:

  • On any x86_64 Linux:

    $ curl https://raw.githubusercontent.com/kamadorueda/alejandra/main/installers/x86_64-linux.sh | sh
  • On any AArch64/ARM64 Linux:

    $ curl https://raw.githubusercontent.com/kamadorueda/alejandra/main/installers/aarch64-linux.sh | sh

Then run Alejandra with:

$ ./alejandra --help

or:

$ /path/to/alejandra --help

Nix installation

  • Nix with Flakes:

    $ nix profile install github:kamadorueda/alejandra
  • Nix stable:

    Pick one depending on your platform:

    $ nix-env -ivA aarch64-darwin -f https://github.com/kamadorueda/alejandra/tarball/main
    $ nix-env -ivA aarch64-linux -f https://github.com/kamadorueda/alejandra/tarball/main
    $ nix-env -ivA x86_64-darwin -f https://github.com/kamadorueda/alejandra/tarball/main
    $ nix-env -ivA x86_64-linux -f https://github.com/kamadorueda/alejandra/tarball/main

Then run Alejandra with:

$ alejandra --help

Do I need to configure anything?

  • No.

Discussion

Cool libraries

Alternatives

See why Alejandra was created and a comparison between alternatives here.

Versioning

We use semver to version Alejandra.

Our public API consists of:

  • The formatting rules (a.k.a. the style).
  • The CLI tool ($ alejandra), command line flags, positional arguments, and stdout.

Changelog

Please see: CHANGELOG.md.

Footnotes

Footnotes

  1. Running on a machine with:

    • CPU: 8 physical x Intel(R) Core(TM) i7-10700K, 16 logical
    • MHz: 3800.00
    • BogoMips: 7599.80
    • Cache Size: 16384 KB

    Results:

    Logical Cores Seconds
    1 45
    2 22
    4 14
    8 10
    16 11
  2. The methodology to claim this is:

    1. Checkout Nixpkgs and run:

      $ nix-env -qaP --json --drv-path > before
      
    2. Now format with Alejandra and run:

      $ nix-env -qaP --json --drv-path > after
      

    As of 2022-02-08, there are 47 differences in a set of 36278 derivations because of things like this:

    goDeps = ./deps.nix;
    

    Since ./deps.nix was also formatted you get a semantical difference.

    This is something that should be solved on Nixpkgs and not a bug in Alejandra. For example: