diff --git a/README.md b/README.md new file mode 100644 index 0000000..f55db66 --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +
The Uncompromising Nix Code Formatter
+ + + +## Getting started + +Let's get Alejandra on our systems: + +- Nix with Flakes: + + ```bash + $ nix run github:kamadorueda/alejandra -- --help + ``` + +- Nix stable: + + Pick one depending on your platform: + ```bash + $ 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 i686-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 with: + + ```bash + $ alejandra --help + ``` + +## Goals + +- ✔️ **Fast** + + It's written in rust + and formats [Nixpkgs](https://github.com/NixOS/nixpkgs) + in under 1 minute. + +- ✔️ **Highly tested** + + Coverage currently > 80%, + aiming to a 💯% soon. + +- ✔️ **Comprehensive** + + All elements in the Nix grammar have a rule, + so there won't be portions of code unformatted. + +- ✔️ **Reproducible** + + Formatting many times yields the same results. + +- 🚧 **Beautiful** + + Beauty is subjective, right? + + Yet there are a few improvements to implement like: + - Multiline strings indentation `'' ... ''`. + - Multiline comments indentation `/* ... */`. + - Not indenting attr sets, lists, or parenthesis after binding `name = {`. + - And many more as community feedback drives. + + Style is negotiable at this moment. + +## Do I need to configure anything? + +- No. diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..0c39827 --- /dev/null +++ b/default.nix @@ -0,0 +1,15 @@ +let + lockData = builtins.readFile ./flake.lock; + lock = builtins.fromJSON lockData; + flakeCompat = lock.nodes.flakeCompat.locked; + flakeCompatSrc = + builtins.fetchTarball + { + url = "https://github.com/edolstra/flake-compat/archive/${ flakeCompat.rev }.tar.gz"; + sha256 = flakeCompat.narHash; + }; + flake = import flakeCompatSrc { src = ./.; }; +in +flake + .defaultNix + .defaultPackage diff --git a/flake.lock b/flake.lock index 006051a..aa71771 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flakeCompat": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flakeUtils": { "locked": { "lastModified": 1642700792, @@ -33,6 +49,7 @@ }, "root": { "inputs": { + "flakeCompat": "flakeCompat", "flakeUtils": "flakeUtils", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index 4d72307..ed2cf35 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,8 @@ { inputs = { + flakeCompat.url = github:edolstra/flake-compat; + flakeCompat.flake = false; flakeUtils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; }; @@ -11,20 +13,15 @@ system: let nixpkgs = import inputs.nixpkgs { inherit system; }; - cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + cargoToml = builtins.fromTOML ( builtins.readFile ./Cargo.toml ); in { checks = { defaultPackage = inputs.self.defaultPackage.${ system }; - inherit (inputs.self.packages.${ system }) nixpkgsFormatted; - }; - defaultApp = - { - type = "app"; - program = - "${ inputs.self.defaultPackage.${ system } }/bin/alejandra"; + inherit ( inputs.self.packages.${ system } ) nixpkgsFormatted; }; + defaultApp = { type = "app"; program = "${ inputs.self.defaultPackage.${ system } }/bin/alejandra"; }; defaultPackage = nixpkgs.rustPlatform.buildRustPackage { @@ -35,9 +32,9 @@ NIX_BUILD_CORES = 0; meta = { - description = inputs.self.description; + description = cargoToml.package.description; homepage = "https://github.com/kamadorueda/alejandra"; - license = nixpkgs.lib.licenses.mit; + license = nixpkgs.lib.licenses.unlicense; maintainers = [ nixpkgs.lib.maintainers.kamadorueda ]; }; }; @@ -69,8 +66,7 @@ git diff --no-index $nixpkgs $out > $diff || true ''; - buildInputs = - [ inputs.self.defaultPackage.${ system } nixpkgs.git ]; + buildInputs = [ inputs.self.defaultPackage.${ system } nixpkgs.git ]; nixpkgs = inputs.nixpkgs.sourceInfo.outPath; NIX_BUILD_CORES = 0; outputs = [ "diff" "out" ];