nix/modules/programs/home/zsh/scripts/rebuild.sh

34 lines
796 B
Bash
Raw Normal View History

2024-08-31 16:04:57 +02:00
#!/bin/sh
2024-08-31 16:55:57 +02:00
current_dir=$(pwd)
2024-10-18 10:48:54 +02:00
cd ~/nix || exit
2024-08-31 16:04:57 +02:00
2024-10-19 19:50:22 +02:00
alejandra .
2024-10-18 10:48:54 +02:00
git fetch
2024-08-31 16:04:57 +02:00
2024-10-18 10:48:54 +02:00
if git diff --quiet HEAD..origin/main; then
echo "No changes detected in the remote. Proceeding with rebuild..."
2024-10-08 15:28:40 +02:00
2024-10-18 10:48:54 +02:00
git add .
2024-08-31 16:55:57 +02:00
2024-10-18 10:48:54 +02:00
hostname=$(hostname)
if echo "$hostname" | grep -q 'desktop'; then
doas nixos-rebuild switch --flake ~/nix/#desktop
elif echo "$hostname" | grep -q 'laptop'; then
doas nixos-rebuild switch --flake ~/nix/#laptop
elif echo "$hostname" | grep -q 'server'; then
doas nixos-rebuild switch --flake ~/nix/#server
elif echo "$hostname" | grep -q 'localhost'; then
nix-on-droid switch --flake ~/nix
fi
else
echo "Changes detected in the remote. Stopping execution."
git diff HEAD..origin/main
exit 1
2024-08-31 16:04:57 +02:00
fi
2024-08-31 16:55:57 +02:00
2024-10-18 10:48:54 +02:00
cd "$current_dir" || exit