nixos/scripts/update-single-machine

33 lines
657 B
Plaintext
Raw Normal View History

2022-01-31 12:28:59 +01:00
#!/usr/bin/env bash
2024-01-15 13:25:22 +01:00
set -e
cd /home/andreas/.nixos
2022-01-31 12:28:59 +01:00
rsa_key="~/.nixos/secrets/ssh_keys/ansible/ansible.key"
2022-01-31 14:31:55 +01:00
export NIX_SSHOPTS="-t -i $rsa_key"
2022-01-31 12:28:59 +01:00
reboot=0
while getopts ":r" option; do
case $option in
r)
reboot=1
host=$2
fqdn="$host.2li.local"
echo "$fqdn with reboot"
nixos-rebuild boot -j auto --use-remote-sudo --target-host $fqdn --flake ".#$host"
ssh -i $rsa_key $fqdn 'sudo reboot'
;;
esac
done
if [ $reboot -eq 0 ]; then
host=$1
fqdn="$host.2li.local"
echo "$fqdn"
nixos-rebuild switch -j auto --use-remote-sudo --target-host $fqdn --flake ".#$host"
fi
echo
echo