added tool for checking deployment requirement
All checks were successful
/ test (push) Successful in 42s

This commit is contained in:
Jermeiah S 2025-06-20 13:54:11 -04:00
parent 7e7384464a
commit a784b12962
No known key found for this signature in database

View file

@ -0,0 +1,44 @@
#!/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