nix/update.sh
2025-08-24 20:24:36 +02:00

31 lines
496 B
Bash

#!/usr/bin/env bash
set -e
pushd ~/nixos/
git add .
alejandra . &>/dev/null \
|| (alejandra . ; echo "formatting failed!" && exit 1)
echo "Updating flake"
nix flake update
echo "Checking for changes"
git restore --staged .
if git diff --quiet ; then
echo "No changes, exiting."
popd
exit 0
fi
git add .
echo "New changes, Rebuilding..."
sudo nixos-rebuild switch --upgrade --flake .
current=$(nixos-rebuild list-generations | grep current)
git commit -am "$current"
git push
popd