nixos/scripts/update-all-machines

46 lines
1016 B
Plaintext
Raw Permalink Normal View History

2022-01-31 12:42:56 +01:00
#!/usr/bin/env bash
2024-01-15 13:25:22 +01:00
set -e
cd /home/andreas/.nixos
2023-11-26 12:14:24 +01:00
hosts=($(echo $(nix eval .#nixosConfigurations --apply 'pkgs: builtins.concatStringsSep " " (builtins.attrNames pkgs)') | xargs))
skip=(
2022-11-03 11:33:58 +01:00
"desktop-vm"
"gwyn"
"loki-test"
2023-04-23 13:47:43 +02:00
"mobile"
2022-11-03 11:33:41 +01:00
"staubfinger"
2023-01-06 19:04:44 +01:00
"test-raspi"
2022-01-31 12:42:56 +01:00
)
2022-01-31 15:45:25 +01:00
rsa_key="$HOME/.nixos/secrets/ssh_keys/ansible/ansible.key"
export NIX_SSHOPTS="-t -i $rsa_key"
2022-11-12 15:28:35 +01:00
reboot=0
while getopts ":r" option; do
case $option in
2023-11-26 12:14:24 +01:00
r)
2022-11-12 15:28:35 +01:00
reboot=1
2023-11-26 12:14:24 +01:00
;;
2022-11-12 15:28:35 +01:00
esac
done
2022-01-31 12:42:56 +01:00
2023-11-26 12:14:24 +01:00
for host in "${hosts[@]}"; do
# Check if the host is in the skip list
2023-11-26 12:14:24 +01:00
if [[ " ${skip[*]} " =~ " ${host} " ]]; then
continue
fi
2022-01-31 12:42:56 +01:00
fqdn="$host.2li.local"
if [ $reboot -eq 0 ]; then
echo $fqdn
2023-12-04 17:21:23 +01:00
nixos-rebuild switch -j auto --use-remote-sudo --target-host $fqdn --flake ".#$host"
else
echo "$fqdn with reboot"
nixos-rebuild boot -j auto --use-remote-sudo --target-host $fqdn --flake ".#$host"
2022-11-12 15:28:35 +01:00
ssh -i $rsa_key $fqdn 'sudo reboot'
fi
2022-05-20 13:29:35 +02:00
echo
echo
done