nixos/scripts/remote_switch.sh

29 lines
713 B
Bash
Raw Normal View History

2022-01-31 12:42:56 +01:00
#!/usr/bin/env bash
set -e
2022-01-31 12:42:56 +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"
2022-11-03 11:33:41 +01:00
"staubfinger"
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-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
nixos-rebuild switch -j auto --use-remote-sudo --build-host localhost --target-host $fqdn --flake ".#$host"
2022-05-20 13:29:35 +02:00
echo "reboot $fqdn"
2022-05-20 13:35:18 +02:00
ssh -i $rsa_key $fqdn 'sudo reboot'
2022-05-20 13:29:35 +02:00
echo
echo
done