1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2026-01-17 02:31:04 +00:00
No description
Find a file
2022-07-13 23:30:53 -06:00
front feat: release 2.0.0 2022-07-13 23:30:53 -06:00
integrations feat: release 2.0.0 2022-07-13 23:30:53 -06:00
src feat: release 2.0.0 2022-07-13 23:30:53 -06:00
.envrc refactor: remove nix3 alias 2022-02-16 21:40:16 -05:00
.gitattributes chore: Ignore the generated list of nixpkgs files for language stats 2022-02-19 10:50:47 -05:00
.gitignore feat: add wasm site 2022-02-13 13:51:20 -05:00
.pre-commit-entry.sh feat: release 2.0.0 2022-07-13 23:30:53 -06:00
.pre-commit-hooks.yaml feat: add system pre-commit hook 2022-05-19 07:39:44 -06:00
buildkite.yaml feat: rename alejandra_engine to alejandra 2022-06-23 12:55:13 -06:00
Cargo.lock feat: release 2.0.0 2022-07-13 23:30:53 -06:00
Cargo.toml test: add more apply cases 2022-03-02 16:01:12 -05:00
CHANGELOG.md feat: release 2.0.0 2022-07-13 23:30:53 -06:00
CODE_OF_CONDUCT.md docs: add a code of conduct [skip ci] 2022-07-12 13:19:55 -06:00
CONTRIBUTING.md docs: add a contributing file [skip ci] 2022-07-12 13:17:51 -06:00
default.nix feat: simplify nix stable installation 2022-06-23 12:38:08 -06:00
flake.lock feat: update dependencies 2022-07-13 23:02:00 -06:00
flake.nix feat: release 2.0.0 2022-07-13 23:30:53 -06:00
README.md feat: release 2.0.0 2022-07-13 23:30:53 -06:00
rustfmt.toml refactor: use more rustfmt rules 2022-07-10 12:23:42 -06:00
STYLE.md docs: link discussions [skip ci] 2022-07-12 13:22:36 -06:00
treefmt.toml docs: update changelog 2022-02-21 13:08:13 -05:00
UNLICENSE feat: release into the public domain 2022-01-09 22:14:23 -05:00

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 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:

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/2.0.0
    
  • Nix with Flakes:

    $ nix profile install github:kamadorueda/alejandra/2.0.0
    

Then run Alejandra with:

$ alejandra --help

NixOS installation

  • Nix stable:

    let
      alejandra =
        (import (builtins.fetchTarball {
          url = "https://github.com/kamadorueda/alejandra/tarball/2.0.0";
          sha256 = "0000000000000000000000000000000000000000000000000000";
        }) {})
        .outPath;
    in {
      environment.systemPackages = [alejandra];
    }
    
  • Nix with Flakes:

    {
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    
        alejandra.url = "github:kamadorueda/alejandra/2.0.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 ❤️

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

    Using:

    # x86_64-unknown-linux-gnu
    $ time alejandra --threads $threads /path/to/nixpkgs
    

    Results:

    $threads Seconds
    1 13.4
    2 6.9
    4 3.6
    8 2.6
    16 3.1
    ↩︎
  2. The methodology to claim this is:

    1. Checkout Nixpkgs and run:

      $ nix-env -qaf . --drv-path --xml > before
      
    2. 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:

    ↩︎