mirror of
https://github.com/nix-community/home-manager
synced 2025-01-10 19:19:52 +01:00
1e2a9d2d29
This can cause failures if the user has configuration that is incompatible with the version of git pinned in the format script. Potentially it could have other undesired effects as well. Fix #5736
50 lines
1.1 KiB
Text
Executable file
50 lines
1.1 KiB
Text
Executable file
#! /usr/bin/env nix-shell
|
|
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/6616de389ed55fba6eeba60377fc04732d5a207c.tar.gz -i bash -p git gnugrep gnused findutils nixfmt
|
|
|
|
# Avoid being affected by system and user git config.
|
|
export GIT_CONFIG_NOSYSTEM=1
|
|
export HOME=
|
|
export XDG_CONFIG_HOME=
|
|
|
|
nixfmt_args=()
|
|
files=()
|
|
|
|
for arg do
|
|
case $arg in
|
|
-h)
|
|
echo "$0 [-c]"
|
|
exit
|
|
;;
|
|
-c)
|
|
nixfmt_args+=("$arg")
|
|
;;
|
|
-*)
|
|
echo "unrecognised flag: $arg" >&2
|
|
exit 1
|
|
;;
|
|
*)
|
|
files+=("$arg")
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# The excludes are for files touched by open pull requests and we want
|
|
# to avoid merge conflicts.
|
|
excludes=(
|
|
modules/files.nix
|
|
modules/home-environment.nix
|
|
modules/programs/zsh.nix
|
|
)
|
|
|
|
exclude_args=()
|
|
for e in "${excludes[@]}"; do
|
|
exclude_args+=(-e "$e")
|
|
done
|
|
|
|
git_root=$(git rev-parse --show-toplevel)
|
|
|
|
git ls-files -z --cached --others --full-name -- "${files[@]}" |
|
|
grep -z '\.nix$' |
|
|
grep -z -v "${exclude_args[@]}" |
|
|
sed -z "s|^|$git_root/|" |
|
|
xargs -0 nixfmt "${nixfmt_args[@]}"
|