nixos/scripts/remote_switch.sh

43 lines
965 B
Bash
Raw Normal View History

2022-01-31 12:42:56 +01:00
#!/usr/bin/env bash
cd /home/andreas/.nixos
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
r)
reboot=1
esac
done
2022-01-31 12:42:56 +01:00
2022-01-31 15:45:25 +01:00
for host in "${hosts[@]}"
do
# Check if the host is in the skip list
if [[ " ${skip[*]} " =~ " ${host} " ]];then
continue
fi
2022-01-31 12:42:56 +01:00
fqdn="$host.2li.local"
echo $fqdn
if [ $reboot -eq 0 ]; then
2023-06-19 11:57:40 +02:00
nixos-rebuild switch -j auto --use-remote-sudo --target-host $fqdn --flake ".#$host"
else
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