Archived
6
52
Fork
You've already forked fjo
3

feat(nix): add treefmt #26

Merged
Aviac merged 7 commits from Lord-Valen/fjo:flake-treefmt into main 2024年04月04日 08:37:37 +02:00
Contributor
Copy link

I used the treefmt-nix flakeModule. nix fmt will now run a configured treefmt by default. I chose to use the unstable nixfmt as it is now the official formatter (or it will be on the next stable release), this should save us from large future reformats.

Rustfmt was being annoying so I had to create empty files for the declared but unimplemented modules. I'm not entirely sure why cargo fmt ignores this despite using the same rustfmt version.

I used the treefmt-nix flakeModule. `nix fmt` will now run a configured treefmt by default. I chose to use the unstable nixfmt as it is now the official formatter (or it will be on the next stable release), this should save us from large future reformats. Rustfmt was being annoying so I had to create empty files for the declared but unimplemented modules. I'm not entirely sure why `cargo fmt` ignores this despite using the same rustfmt version.
nixos-unstable doesn't cache builds for darwin
refactor(nix): use lib.getExe'
All checks were successful
ci/woodpecker/pr/check_fmt Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pull_request_closed/check_fmt Pipeline was successful
ci/woodpecker/pull_request_closed/lint Pipeline was successful
ci/woodpecker/pull_request_closed/test Pipeline was successful
fb8b38be27
Owner
Copy link

thanks for the PR!

thanks for the PR!
noth left a comment

looks good to me

looks good to me
@ -64,0 +61,4 @@
in
{
treefmt = {
projectRootFile = ".git/config";

what's the reason behind ".git/config" here? for most its either self or ./.

what's the reason behind ".git/config" here? for most its either `self` or `./.`
Author
Contributor

That's true of projectRoot but not projectRootFile. The wrapped treefmt recursively searches upward from the working directory until it identifies a file which matches this. The location where it found that file is then treated as the root of the project.1 Ideally, we would use a file that's fairly unique for this. I've seen flake.nix and .git/config used (in the docs and in nix-cargo-integration, for example). Ideally, it's going to be a file which is uniquely at the root and will always exist. As long as we use git and don't use submodules, this should be unique, existent, and is more likely to remain so than flake.nix imo.2 In fact, I think that any file has a chance of having a duplicate in the presence of submodules. The solution? Well, if we must use submodules, don't run treefmt in a submodule, I guess. Or perhaps more arduously, create a file with a (reasonably) unique name and use that to identify the project root, but I'm not a fan of cluttering the root with extra files.3


  1. github.com/numtide/treefmt-nix@49dc4a92b0/module-options.nix (L108-L123) ↩︎

  2. Not using flake.nix leaves us open to the possibility of using subflakes without worrying about PWD when we run treefmt. ↩︎

  3. Obviously, that means I'm a little annoyed that rustfmt made me initialize those empty files. ↩︎

That's true of `projectRoot` but not `projectRootFile`. The wrapped treefmt recursively searches upward from the working directory until it identifies a file which matches this. The location where it found that file is then treated as the root of the project.[^1] Ideally, we would use a file that's fairly unique for this. I've seen `flake.nix` and `.git/config` used (in the docs and in nix-cargo-integration, for example). Ideally, it's going to be a file which is uniquely at the root and will always exist. As long as we use git and don't use submodules, this should be unique, existent, and is more likely to remain so than flake.nix imo.[^2] In fact, I think that any file has a chance of having a duplicate in the presence of submodules. The solution? Well, if we must use submodules, don't run treefmt in a submodule, I guess. Or perhaps more arduously, create a file with a (reasonably) unique name and use that to identify the project root, but I'm not a fan of cluttering the root with extra files.[^3] [^1]: https://github.com/numtide/treefmt-nix/blob/49dc4a92b02b8e68798abd99184f228243b6e3ac/module-options.nix#L108-L123 [^2]: Not using flake.nix leaves us open to the possibility of using subflakes without worrying about PWD when we run treefmt. [^3]: Obviously, that means I'm a little annoyed that rustfmt made me initialize those empty files.

that could be .envrc

that could be .envrc
Author
Contributor

Sure, but somebody could remove .envrc, there also are motivations for having such files in subdirectories. Not to mention it doesn't evade the whole submodule issue. Nobody will remove .git/config (at least, no contributor). It's also more portable since not all git repos will have a .envrc, but they will have a .git/config.

Sure, but somebody *could* remove .envrc, there also are motivations for having such files in subdirectories. Not to mention it doesn't evade the whole submodule issue. Nobody will remove .git/config (at least, no contributor). It's also more portable since not all git repos will have a .envrc, but they will have a .git/config.
noth marked this conversation as resolved
Aviac left a comment

Looks good, thanks for the contribution!

Looks good, thanks for the contribution!
Aviac referenced this pull request from a commit 2024年04月04日 08:37:37 +02:00
Commenting is not possible because the repository is archived.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
VoiDD/fjo!26
Reference in a new issue
VoiDD/fjo
No description provided.
Delete branch "Lord-Valen/fjo:flake-treefmt"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?