nixconfig/scripts/nh-push
2025-07-01 01:28:13 -07:00

27 lines
No EOL
806 B
Bash
Executable file

#!/usr/bin/env bash
# A wrapper for 'nh' that runs 'git pull' and 'git push' on success.
# Exit immediately if a command exits with a non-zero status.
set -e
# Determine the absolute path of the directory containing this script.
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# The repository root is one level above the scripts directory.
REPO_ROOT="$SCRIPT_DIR/.."
# --- Git Operations ---
echo "Pulling latest changes from git..."
# Use -C to specify the repository path for git operations.
git -C "$REPO_ROOT" pull
# --- NixOS Build ---
echo "Building NixOS configuration..."
# Use --flake to specify the flake path.
nh os switch ".#$@"
# --- Git Push on Success ---
echo "NixOS rebuild successful. Pushing to remote..."
git -C "$REPO_ROOT" push
echo "Push complete."