Awesome
<h1 align="center">Alejandra 💅</h2> <p align="center">The Uncompromising Nix Code Formatter</p> <p align="center"> <a href="https://buildkite.com/kamadorueda/alejandra" > <img alt="CI/CD" src="https://badge.buildkite.com/67d170860f5630bbc776a97fb0be9c88a97c92860c91f77aa0.svg?branch=main" > </img> </a> <a href="https://coveralls.io/github/kamadorueda/alejandra?branch=main" > <img alt="Coverage" src="https://coveralls.io/repos/github/kamadorueda/alejandra/badge.svg?branch=main" > </img> </a> <a href="https://github.com/kamadorueda/alejandra/blob/main/UNLICENSE" > <img alt="License: The Unlicense" src="https://img.shields.io/badge/license-The Unlicense-green.svg" > </a> <a href="https://github.com/kamadorueda/alejandra" > <img alt="style: Alejandra" src="https://img.shields.io/badge/code%20style-Alejandra-green.svg" > </a> </p> <p align="center"> Try it on your browser! <a href="https://kamadorueda.github.io/alejandra/" > here </a> </p>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 original style of Nixpkgs, and then we applied the feedback of developers who have used Nix at scale for several years, producing a very well-grounded style guide.
-
✔️ 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 and workflows:
Getting started
On the web editor
Please visit: kamadorueda.github.io/alejandra.
Prebuilt binaries
You can download a binary for your platform:
- aarch64-unknown-linux-musl
- armv6l-unknown-linux-musleabihf
- armv7l-unknown-linux-musleabihf
- i686-unknown-linux-musl
- x86_64-unknown-linux-musl
Make it executable ($ chmod +x
)
and run Alejandra with:
$ ./alejandra --help
or:
$ /path/to/alejandra --help
From Nixpkgs
Please visit: search.nixos.org/packages?query=alejandra.
Nix installation
-
Nix stable:
$ nix-env -ivf https://github.com/kamadorueda/alejandra/tarball/3.1.0
-
Nix with Flakes:
$ nix profile install github:kamadorueda/alejandra/3.1.0
Then run Alejandra with:
$ alejandra --help
NixOS installation
-
Nix stable:
let alejandra = (import (builtins.fetchTarball { url = "https://github.com/kamadorueda/alejandra/tarball/3.1.0"; sha256 = "0000000000000000000000000000000000000000000000000000"; }) {}) .outPath; in { environment.systemPackages = [alejandra]; }
-
Nix with Flakes:
{ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; alejandra.url = "github:kamadorueda/alejandra/3.1.0"; alejandra.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = {alejandra, nixpkgs, ...}: { nixosConfigurations = { example = nixpkgs.lib.nixosSystem rec { # We support: aarch64-darwin, aarch64-linux, i686-linux, x86_64-darwin, x86_64-linux system = "x86_64-linux"; modules = [ { environment.systemPackages = [alejandra.defaultPackage.${system}]; } # Import your other modules here # ./path/to/my/module.nix # ... ]; }; }; }; }
Do I need to configure anything?
- No.
Discussion
Cool libraries
Alternatives
See why Alejandra was created and a comparison between alternatives here.
Alternatively, checkout the code examples of the different formatters 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, exit codes, and stdout.
Changelog
Please read: CHANGELOG.
Contributors
The following people have helped improving Alejandra.
Thank you ❤️
- Kevin Amado ~ Email, LinkedIn.
- Thomas Bereknyei.
- Piegames.
- Joachim Ernst.
- David Arnold.
- David Hauer.
- Ryan Mulligan.
- Fabian Möller.
- Rok Garbas.
- Yorick van Pelt.
- Rehno Lindeque.
- Rebecca Turner.
- Jörg Thalheim.
- Nathan Henrie.
- Vincent Ambo.
- Jamie Quigley.
- Loïc Reynier.
- Mr Hedgehog.
- Tobias Bora.
- Tristan Maat.
- Victor Engmark.
- UserSv4.
- Michael Utz.
- Pablo Ovelleiro Corral.
- Norbert Melzer.
- Patrick Stevens.
- Connor Baker.
- Matthew Kenigsberg.
- Florian Finkernagel.
Footnotes
Footnotes
-
Running on a machine with:
- CPU: 4 physical, 4 logical, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
- MHz: from 400 to 4700 MHz
- BogoMips: 5606.40
- Cache L3: 12 MiB
Using:
# x86_64-unknown-linux-gnu $ time alejandra --threads $threads /path/to/nixpkgs
Results:
↩$threads Seconds 1 45 2 25 4 14 -
The methodology to claim this is:
-
Checkout Nixpkgs and run:
$ nix-env -qaf . --drv-path --xml > before
-
Now format with Alejandra and run:
$ nix-env -qaf . --drv-path --xml > after
As of 2022-06-22, there are 41 differences in a set of 38109 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:
↩ -