tomberek / alejandra

The Uncompromising Nix Code Formatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alejandra 💅

The Uncompromising Nix Code Formatter

CI/CD Coverage License: The Unlicense style: Alejandra

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 optimize for the wisdom of the crowd, which comes in big part from the 2.3 million lines of code of Nixpkgs.

  • ✔️ Transparent

    You won't notice the formatter after a while.

    Humans care about the content, machines about the style!

Getting started

Let's get Alejandra on our systems:

  • Nix with Flakes:

    $ nix run github:kamadorueda/alejandra -- --help
  • Nix stable:

    Pick one depending on your platform:

    $ 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 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.

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:

About

The Uncompromising Nix Code Formatter

License:The Unlicense


Languages

Language:Rust 96.3%Language:Nix 2.9%Language:Shell 0.9%