fix(ci.formatting): use nixfmt --check to avoid writing to read-only nix store#548
Conversation
1649d42 to
3d36ff4
Compare
|
Please excuse the amount of changes and CI runs related to this PR. The fix is CI-related so I had to re-run CI to test my solution |
|
While it feels a little weird to run a different command to test the formatting than the users run, nixfmt and nixfmt-tree are both using the same formatter, so, that is fine. The message is definitely better.
Hey, I mean, its github's dime not mine :) Let me try it out, but, seems good? |
|
Yeah after trying out all the options for treefmt, it would appear there is no way to prevent it from throwing the bad error. This seems fine to me. Maybe one day they fix it and we can swap it back |
find has this feature, and it also batches the files but automatically respects whatever ARG_MAX is. Lets use that instead of `find -print0 | xargs -0` in the interest of only using 1 program for gathering the args Context: #548 I forgot how find worked due to learning about the `find -print0 | xargs -0` trick for the first time The resulting log output is the same.
|
@BirdeeHub yeah I figured you'd want to make this change now, and then when the original issue gets fixed or they add a --check flag or something we could swap back. |
Summary
When a file needs reformatting and the formatting-check derivation is not cached,
nixfmt-treecrashes with a crypticPermission deniederror instead of reporting which file needs fixing.The root cause: nixfmt writes the reformatted output to a temp file in the same directory as the source file (for atomic in-place replacement). When the source is a read-only Nix store path, this fails. The crash only occurs when a file actually needs reformatting -- if files are already correctly formatted, nixfmt makes no writes and the check passes fine. So the bug is masked for contributors who run
nix fmtlocally before submitting.Fix: replace the
nixfmt-treeinvocation withnixfmt --check, which reads files without writing anything and exits cleanly with<file>: not formattedfor any improperly formatted files. As a bonus this produces a much more useful error message.Example of the unhelpful crash:
What the fix produces instead:
The bug was first introduced in c11bd23 when
nixfmt-treewas added as the formatter. It has been masked because contributors generally runnix fmtlocally, and the Nix derivation cache means the check only re-runs when the source tree hash changes.Given that this is all avoided by running
nix fmtlocally, it'd make perfect sense if you'd like to stick withnixfmt-treeand close this PR, but I thought I should at least put the solution out there, in case anyone else found it annoying.Test plan
checks.aarch64-darwin.wlib-formattingpasses on macOS CIchecks.x86_64-linux.wlib-formattingpasses on Linux CI.nixfile produces a clear "not formatted" error rather than a crash