44 lines
1.1 KiB
Bash
Executable file
44 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Check for hostname argument
|
|
if [[ $# -ne 1 ]]; then
|
|
echo "Usage: $0 <nixos-hostname>"
|
|
exit 1
|
|
fi
|
|
|
|
HOST="$1"
|
|
REPO_PATH="git+file://$PWD"
|
|
|
|
CURRENT_COMMIT=$(git rev-parse HEAD)
|
|
PREV_COMMIT=$(git rev-parse HEAD^)
|
|
|
|
# Check if the host exists at the current commit
|
|
if ! nix eval --quiet --expr "
|
|
let
|
|
flake = builtins.getFlake \"${REPO_PATH}?rev=${CURRENT_COMMIT}\";
|
|
in
|
|
builtins.hasAttr \"${HOST}\" flake.nixosConfigurations
|
|
"; then
|
|
echo "Error: Host '${HOST}' not found in nixosConfigurations at HEAD."
|
|
exit 1
|
|
fi
|
|
|
|
# Now check for derivation change
|
|
RESULT=$(nix eval --raw --expr "
|
|
let
|
|
flake = builtins.getFlake;
|
|
prev = flake \"${REPO_PATH}?rev=${PREV_COMMIT}\";
|
|
curr = flake \"${REPO_PATH}?rev=${CURRENT_COMMIT}\";
|
|
in
|
|
if prev.nixosConfigurations.\"${HOST}\".config.system.build.toplevel !=
|
|
curr.nixosConfigurations.\"${HOST}\".config.system.build.toplevel
|
|
then \"changed\" else \"unchanged\"
|
|
")
|
|
|
|
# Output result
|
|
if [[ $RESULT == "changed" ]]; then
|
|
echo "System derivation changed for host '${HOST}' — deploy!"
|
|
else
|
|
echo "No change for host '${HOST}' — skip deployment."
|
|
fi
|