mirror of
https://github.com/Death916/nixconfig.git
synced 2026-04-10 02:54:39 -07:00
42 lines
No EOL
1.4 KiB
Bash
Executable file
42 lines
No EOL
1.4 KiB
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=$(realpath "$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
|
|
|
|
# --- Snapshot Creation (Laptop only) ---
|
|
if [ "$(hostname)" = "nixos" ]; then
|
|
echo "Creating Btrfs snapshots for /nix and /home..."
|
|
sudo btrfs subvolume snapshot -r /nix "/snapshots/nix_$(date +%Y-%m-%d_%H%M)"
|
|
sudo btrfs subvolume snapshot -r /home "/snapshots/home_$(date +%Y-%m-%d_%H%M)"
|
|
echo "Snapshots created."
|
|
fi
|
|
|
|
# --- NixOS Build ---
|
|
echo "Building NixOS configuration..."
|
|
# If an argument is provided, use it as the hostname with -H.
|
|
# Otherwise, let nh autodetect the hostname.
|
|
if [ -z "$1" ]; then
|
|
echo "Running: nh os switch $REPO_ROOT"
|
|
nh os switch "$REPO_ROOT"
|
|
else
|
|
echo "Running: nh os switch $REPO_ROOT -H $@"
|
|
nh os switch "$REPO_ROOT" -H "$@"
|
|
fi
|
|
|
|
# --- Git Push on Success ---
|
|
echo "NixOS rebuild successful. Pushing to remote..."
|
|
git -C "$REPO_ROOT" push
|
|
|
|
echo "Push complete." |