2020-02-01 19:59:49 +00:00
|
|
|
#! /usr/bin/env nix-shell
|
2023-06-27 21:32:30 +00:00
|
|
|
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/6616de389ed55fba6eeba60377fc04732d5a207c.tar.gz -i bash -p git gnugrep gnused findutils nixfmt
|
2020-02-01 19:59:49 +00:00
|
|
|
|
2023-06-27 21:32:30 +00:00
|
|
|
nixfmt_args=()
|
|
|
|
files=()
|
2020-02-01 19:59:49 +00:00
|
|
|
|
2023-06-27 21:32:30 +00:00
|
|
|
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
|
2020-02-01 19:59:49 +00:00
|
|
|
|
2021-10-31 09:32:58 +00:00
|
|
|
# The excludes are for files touched by open pull requests and we want
|
|
|
|
# to avoid merge conflicts.
|
2023-06-27 21:32:30 +00:00
|
|
|
excludes=(
|
|
|
|
modules/default.nix
|
|
|
|
modules/files.nix
|
|
|
|
modules/home-environment.nix
|
|
|
|
modules/lib/default.nix
|
|
|
|
modules/lib/file-type.nix
|
|
|
|
modules/misc/news.nix
|
|
|
|
modules/programs/ssh.nix
|
|
|
|
modules/programs/zsh.nix
|
|
|
|
tests/default.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[@]}"
|