infra-rebuild/infra-rebuild.sh
June 946ab46275
Add initial scripts, which make up the infra-rebuild tool
infra-rebuild is a simple NixOS deployment tool, which simply uses
nixos-rebuild internally, but tries to make it more convenient to deploy
infrastructure.

It supports most of the nixos-rebuild operations - build, build-vm,
build-vm-with-bootloader, switch, boot, test - but also provides a
reboot operation, which runs nixos-rebuild boot followed by initiating a
reboot.

The tool doesn't need any configuration for a standard use case. It
tries to get the hosts FQDN from its NixOS configuration and tries to
deploy to it. However for special cases, where a custom target hostname,
user or port is needed, it allows one to define those in a
deployment_configuration.json.

infra-rebuild also allows for multiple hosts to be specified at once.
The tool then simply runs the specified operation for each host
sequentially.

Much inspiration was taken from bij.
See here: https://git.clerie.de/clerie/bij
And inspiration was also taken from Colmena.
See here: https://github.com/zhaofengli/colmena
2024-05-28 00:14:29 +02:00

40 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
REAL_BASE_DIR=$( dirname $( realpath "$0" ) )
if [ $# -lt 2 ] || [ $# -gt 2 ]; then
$REAL_BASE_DIR/helper/msg_error.sh "\
Error: Incorrect amount of arguments given.
You need to provide exactly two arguments. The first one being the operation you want to run and the second one being the host or hosts (comma separated) you want to run the operation for."
exit 1
fi
OPERATION="$1"
HOSTS="$2"
case $OPERATION in
build|build-vm|build-vm-with-bootloader|switch|boot|test|reboot)
;;
*)
$REAL_BASE_DIR/helper/msg_error.sh "\
Error: No valid operation given.
The operation must be one of:
build, build-vm, build-vm-with-bootloader, switch, boot, test, reboot."
exit 1
;;
esac
set -e
for HOST in ${HOSTS//,/ }; do
case $OPERATION in
build|build-vm|build-vm-with-bootloader)
env OPERATION="$OPERATION" HOST="$HOST" $REAL_BASE_DIR/operations/local.sh
;;
switch|boot|test|reboot)
env OPERATION="$OPERATION" HOST="$HOST" $REAL_BASE_DIR/operations/remote.sh
;;
esac
done