Giter Site home page Giter Site logo

mic92 / alejandra Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamadorueda/alejandra

0.0 1.0 0.0 1.01 MB

The Uncompromising Nix Code Formatter

Home Page: https://kamadorueda.github.io/alejandra/

License: The Unlicense

Nix 29.00% Rust 66.21% Shell 0.49% JavaScript 4.02% HTML 0.28%

alejandra's Introduction

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:

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

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

    Pick one depending on your platform:

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

Then run Alejandra with:

$ alejandra --help

NixOS installation

  • Nix with Flakes:

    {
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    
        alejandra.url = "github:kamadorueda/alejandra/1.0.0";
        alejandra.inputs.nixpkgs.follows = "nixpkgs";
      };
    
      outputs = {alejandra, nixpkgs, ...}: {
        nixosConfigurations = {
          example = nixpkgs.lib.nixosSystem rec {
            # We support: aarch64-linux, aarch64-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
              # ...
            ];
          };
        };
      };
    }
  • Nix stable:

    let
      alejandra =
        (import (builtins.fetchTarball {
          url = "https://github.com/kamadorueda/alejandra/tarball/1.0.0";
          sha256 = "0000000000000000000000000000000000000000000000000000";
        }))
        # Pick one from: aarch64-linux, aarch64-linux, x86_64-darwin, x86_64-linux
        .x86_64-linux
        .outPath;
    in {
      environment.systemPackages = [alejandra];
    }

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, exit codes, 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

    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 -qaP --json --drv-path > before
      
    2. Now format with Alejandra and run:

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

    As of 2022-02-21, there are 46 differences in a set of 36314 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:

    โ†ฉ

alejandra's People

Contributors

blaggacao avatar kamadorueda avatar pyrox0 avatar tazjin avatar tomberek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.