I just wanted to say that this is really awesome, thank you for your hard work on this formatter, looking forward to switching to it once the package hits stable (or I decide nixfmt
annoys me enough I should grab the flake)
This looks like fun, i will give it a whirl, because i need something to keep nix code under controlā¦
However, i donāt think any software has no bugs, maybe āfew bugsā or no-known bugsā¦ iāve never seen a program that as complex as this without bugsā¦
unless, itās magic!
Challenge accepted
Thank you!
I just added a few statically linked pre-built binaries (less than 2MB each), so it is as easier as possible to get started
No need to grab any flake!
hello and thank you for your very cool project
I have installed both the package in my nixos machine as well as the vscode extension
Everything seems to be working
I only see a bug for now.
i first applied alejandra in all of my nix files then commit / push
when i update a file this is what i see now
Iām happy for this!
Yes, this was a recent change, we processed the feedback of Nix experts over time and finally decided to favor the one you see to the right of your image
More about the rationale behind this decision can be found here:
- Leading commas are unhandy Ā· Issue #95 Ā· kamadorueda/alejandra Ā· GitHub
- Trailing commas Ā· Issue #248 Ā· nix-community/nixpkgs-fmt Ā· GitHub
We are cleaning up things before going for a 1.0 release
Is it intentional that same-line comments get flushed onto the next line?
The result becomes quite confusing to read:
- (import ./cfg.nix) { allowEnv = true; }; # if no config is given allow env
+ else (import ./cfg.nix) { allowEnv = true; };
+ # if no config is given allow env
Claiming this has no bugs has been a wise strategy because it has mobilized many people to prove it wrong.
Hi! As someone who worked on nixfmt
, Iād like to defend it for a bit.
Correctness: alejandra is far from perfect, try to format e.g. ''foo''\''bar''
and notice the changed semantics. These escapes are hard
Speed: nixfmt is designed to format all of nixpkgs in under half a minute, on a medium-powered laptop from 2016. Weāll try to reproduce your ten-minute case, but please tell us how you tested this.
This turns your comparison into (emoji table):
| Correctness | Totality | Speed
------------+-------------+----------+----------
nixpkgs-fmt | ā design | ā design | ā
nixfmt | ā bugs | ā
| ??
alejandra | ā bugs | ā
| ā
Good catch! I confirm
What are your thoughts on the fact that Alejandra only causes 46 rebuilds in a set of 36000 derivations (Nixpkgs), vs that nixfmt
actually breaks the build, vs that nixpkgs-fmt
causes near 100% rebuilds ?
I agree no formatter is correct from the theoretical point of view (itās impossible) but Alejandra is correct from a practical (2.3 millions lines of code of Nixpkgs) point of view
Hello everyone,
I recently realized that my messaging
around the discourse post for Alejandra
where I compared different Nix formatting tools
can make people feel personally attacked
I want to apologize for this
The work on Alejandra is only possible because the previous projects,
I have personally used such formatters at work for many years.
Thank you
Truth be told,
I was excited about the tool I just created
and got carried away with so much enthusiasm that I forgot that
we are not just engineers,
but also humans with feelings,
and most importantly,
a community around a common goal.
My only wish is that Nix will have the best possible formatter
I will remove or edit the posts or announcements where I have made an inappropriate comparison
And I also ask for the understanding and forgiveness of the people involved
I think were going to be implementing this formatter, not because the others are crap or badly designed or coded, just because we like it.
Is there anyway it can be ruled based, how much effort would it be to make it rule based, can we send you $$$ to make that feature happen?
Hey @kamadorueda, donāt worry about it.
How I see it, nixpkgs-fmt
is 99% there but itās always the last tiny percentage that takes a lot of energy. Personally, I am a bit burned out on the project, and so far nobody stepped up to take over the nixpkgs-fmt maintenance.
If itās easier for you to rewrite rather than contribute, thatās fine by me. Sometimes it takes less energy to write things from scratch. You own the whole design, rather than slowly moving a project to the desired state. Plus youāre re-using the rnix-parser so that counts as a win to me
I donāt know what you wrote but I would assume that it was coming from a place of being enthusiastic. I donāt know for others but Iād rather you keep your enthusiasm and not worry about roughing a few feathers. Keep up the good work!
Could you please help me understand what the expected outcome/user experience would be?
If it improves the project, letās do it!
Hey, iām sorry you feel burned out on the project, it happensā¦ Me being a cybernetic robot from the future, a majority people donāt understand even robots from skynet, have energy levels.
Iām adding a text-user interface:
In this PR:
https://github.com/kamadorueda/alejandra/pull/164
Would be very happy if you help me test it in your own terminal or operative system before merging
Thanks @kamadorueda for the nice words.
I think alejandraās current rules-based formatting is more inviting to collaborators and more maintainable, and that going for Rust will easy adoption.
We spent a while looking for bugs and found a few, which Iāll put on the github issue tracker. Sadly, they are mostly rnix-parser related, and I think that project will need some contributions to make alejandra the bug-free formatter it aspires to be .
Another thing thatās very useful to do (and that we did in nixfmt development) is looking at formatted nixpkgs diffs, prioritizing the files that have different outputs on nix-instantiate --parse
.
Thank you! any type of engagement with the project is highly appreciated.
Besides, itās helping us improve things and thatās awesome!
I frequently ask myself if it would be more valuable (as community effort) to just rewrite that component of Nix to allow other programs to see the code as Nix would see it. Instead of creating a non-official library that just tries to mimic the Nix parsing behaviour (and will by definition differ from the official one)
I think a good idea would be an increased modularization of Nix as a whole (this would also make it easier for partial reimplementations of Nix, so that components can be swapped out); some of this is also a goal of https://riir-nix.github.io/, which I initiated with some enthusiasm, but some adjacent projects proved to be more difficult than expected (e.g. GitHub - YZITE/nix2js: [not yet usable] transpile Nix to Javascript using Rust, also uses rnix-parser
, and I also reported some bugsā¦, and fixed one or so). My proposal would be to provide a shared interface, such that the lexer-parser part (itās complex, because of the string handling in Nix, it needs to toggle between lexing and parsing) of nix can be swapped out with some wrapper built on top of rnix-parser
.
It would then be possible to build a fuzzer which makes sure that the implementations handle all valid input the same way, or such.