27 lines
567 B
Bash
Executable File
27 lines
567 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
if git diff --quiet '*.nix'; then
|
|
echo "No changes detected, exiting"
|
|
exit 0
|
|
fi
|
|
|
|
alejandra . &>/dev/null ||
|
|
(
|
|
alejandra .
|
|
echo "formatting failed!" && exit 1
|
|
)
|
|
|
|
git diff -U0 '*.nix'
|
|
|
|
echo "NixOS rebuilding..."
|
|
|
|
sudo nixos-rebuild switch --impure --flake . &>nixos-switch.log || (cat nixos-switch.log | grep --color error && exit 1)
|
|
|
|
current=$(nixos-rebuild list-generations --json | jq '.[] | select (.current == true) | "\(.generation) \(.date) \(.nixosVersion) \(.kernelVersion)"')
|
|
|
|
git commit -am "$current"
|
|
|
|
echo "OK"
|