Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format using nixfmt-rfc-style #1526

Closed
wants to merge 1 commit into from
Closed

Conversation

0x50F1A
Copy link

@0x50F1A 0x50F1A commented Jun 26, 2024

Since RFC 0166 is now merged, pkgs.nixfmt-rfc-style can format nix files to be conformant.

This has some upsides such as:

  • Formatting matches what consumers might expect if they are coming from nixpkgs
  • Deprecated patterns such as URL literals can be automatically fixed

The latter is relevant to some use cases.
For example, users on later versions of nix or those who set the no-url-literals experimental feature cannot evaluate URL literals.
If a package depends on the OCaml Nix Overlays with these features, it will error out and fail to build.

This merge would format the repository to the RFC 0166 standard using pkgs.nixfmt-rfc-style and adopt all the automatic fixes it brings along.

@0x50F1A
Copy link
Author

0x50F1A commented Jun 26, 2024

This was inspired by a real world use case:

Building @faldor20 's https://github.com/faldor20/jj_tui

Will fail to build on versions of Nix that have fully deprecated URL literals due to packages such as ansi being declared with a URL literal

url = https://github.com/ocurrent/ansi/releases/download/0.7.0/ansi-0.7.0.tbz;

An alternative fix could be to do a tree-wide replacement of URL literals with strings containing a URL.

@anmonteiro
Copy link
Collaborator

Thanks. before I take a closer look, could you point me to more information as to why URL literals were deprecated?

@0x50F1A
Copy link
Author

0x50F1A commented Jun 26, 2024

The short of it is here in the manual

The deprecation was RFC 0045

NixOS enforces this treewide.

@anmonteiro
Copy link
Collaborator

anmonteiro commented Jun 26, 2024

This sounds like a good change.

we run find . -iname '*.nix' | xargs nix shell -f ./ nixpkgs-fmt -c nixpkgs-fmt --check in CI, though, and it's saying 125/139 files would be reformatted. It might not be related specifically to the URL change, though.

@0x50F1A
Copy link
Author

0x50F1A commented Jun 26, 2024

nixpkgs-fmt and nixfmt (-rfc-style) diverge significantly, so that makes sense.

This PR effectively endorses moving from nixpkgs-fmt to nixfmt to be RFC compliant.

nixfmt provides a nixfmt --check . which outputs in the following format:

nix-overlays-upstream on master
-> nixfmt --check .

./flake.nix: not formatted
./ci/hydra_jobs.nix: not formatted
./ci/filter.nix: not formatted
./ci/default.nix: not formatted
./ci/hydra.nix: not formatted
./cockroachdb/generic.nix: not formatted
./cockroachdb/default.nix: not formatted
./ocaml/janestreet-0.16.nix: not formatted
./ocaml/overlay-ocaml-packages.nix: not formatted
./ocaml/subscriptions-transport-ws/default.nix: not formatted
./ocaml/piaf/carl.nix: not formatted
./ocaml/piaf/default.nix: not formatted
./ocaml/redis/lwt.nix: not formatted
...
./static/default.nix: not formatted

nix-overlays-upstream on master
->

Part of this PR could be moving to a more canonical approach such as setting the formatter and check attributes of the flake.nix, and running in CI via nix check.

@anmonteiro
Copy link
Collaborator

Part of this PR could be moving to a more canonical approach such as setting the formatter and check attributes of the flake.nix, and running in CI via nix check.

this sounds good to me. would you do this in a separate PR so that I can better assess the diff?

then we could rebase this one on top, which would just be changing the URL strings

@anmonteiro
Copy link
Collaborator

#1541 changed URLs to plain strings.

Feel free to propose a separate PR changing the formatter.

@anmonteiro anmonteiro closed this Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants