June
946ab46275
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
46 lines
1.3 KiB
Bash
Executable file
46 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
REAL_BASE_DIR=$( dirname $( realpath "$0" ) )
|
|
|
|
# Wrapper for nixos-rebuild operations, which act locally.
|
|
|
|
# Takes the following arguments supplied as environment variables.
|
|
# HOST: The host as defined in nixosConfigurations.
|
|
# OPERATION: The nixos-rebuild operation to execute. Can be one of:
|
|
# build, build-vm, build-vm-with-bootloader
|
|
# All operations are as defined in the nixos-rebuild man page.
|
|
|
|
if [ -z $HOST ]; then
|
|
$REAL_BASE_DIR/../helper/msg_error.sh "\
|
|
Internal Error: No host given.
|
|
A host needs to be provided via the HOST environment variable."
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z $OPERATION ]; then
|
|
$REAL_BASE_DIR/../helper/msg_error.sh "\
|
|
Internal Error: No operation given.
|
|
An operation needs to be provided via the OPERATION environment variable."
|
|
exit 1
|
|
fi
|
|
|
|
case $OPERATION in
|
|
build|build-vm|build-vm-with-bootloader)
|
|
;;
|
|
*)
|
|
$REAL_BASE_DIR/../helper/msg_error.sh "\
|
|
Internal Error: No valid operation given.
|
|
The operation provided via the OPERATION environment variable needs to be one of:
|
|
build, build-vm, build-vm-with-bootloader."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
|
|
set -e
|
|
|
|
$REAL_BASE_DIR/../helper/msg_info.sh "\
|
|
Running nixos-rebuild $OPERATION for $HOST..."
|
|
|
|
nixos-rebuild "$OPERATION" --flake ".#$HOST"
|