1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00
home-manager/format
Andrew Marshall 98f4fef7fd format: Fix failing due to no cache access
We change `$HOME` to something not writable, but newer treefmt fails if
it cannot write. We could use a tmpdir, but there’s not much point to a
cache that will be removed, as just add the flag to not use the cache.
2025-04-24 23:33:54 -05:00

35 lines
895 B
Text
Executable file

#! /usr/bin/env nix-shell
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/42a1c966be226125b48c384171c44c651c236c22.tar.gz -i bash -p git gnugrep gnused findutils nixfmt-tree
# Avoid being affected by system and user git config.
export GIT_CONFIG_NOSYSTEM=1
export HOME=/var/empty
export XDG_CONFIG_HOME=/var/empty
nixfmt_args=()
files=()
for arg do
case $arg in
-h)
echo "$0 [-c]"
exit
;;
--ci)
nixfmt_args+=("$arg")
;;
-*)
echo "unrecognised flag: $arg" >&2
exit 1
;;
*)
files+=("$arg")
;;
esac
done
git_root=$(git rev-parse --show-toplevel)
git ls-files -z --cached --others --full-name -- "${files[@]}" |
grep -z '\.nix$' |
sed -z "s|^|$git_root/|" |
xargs -0 treefmt --no-cache "${nixfmt_args[@]}"