Format whole flake when fmt has no args

Now that Nix/Lix do not pass `.` by default for `nix fmt` we can take
`nix fmt` without an arg to mean to format the entire flake.
This commit is contained in:
Archit Gupta 2025-01-26 20:32:19 -08:00
parent 0c583d705e
commit 836107752b

View File

@ -42,7 +42,17 @@ in
in
pkgs.writeShellScriptBin "formatter" ''
PATH=${if fullContext then "" else makeBinPath packages}
if [ $# -eq 0 ]; then exec "$0" .; fi
if [ $# -eq 0 ]; then
flakedir=.
while [ "$(${coreutils}/bin/realpath "$flakedir")" != / ]; do
if [ -e "$flakedir/flake.nix" ]; then
exec "$0" "$flakedir"
fi
flakedir="$flakedir/.."
done
echo Failed to find flake root! >&2
exit 1
fi
for f in "$@"; do
if [ -d "$f" ]; then
${fd}/bin/fd "$f" -Htf -x "$0" &