nh script update

This commit is contained in:
death916 2025-06-30 15:16:38 -07:00
parent 945b913d83
commit cee54def46
3 changed files with 23 additions and 11 deletions

View file

@ -22,4 +22,8 @@
systemctl-tui
gemini-cli
];
programs.bash.shellAliases = {
nh-push = "/home/death916/nixconfig/scripts/nh-push";
};
}

View file

@ -144,6 +144,7 @@ in
homelab = "tailscale ssh homelab";
urldecode = "python3 -c 'import sys, urllib.parse as ul; print(ul.unquote_plus(sys.stdin.read()))'";
urlencode = "python3 -c 'import sys, urllib.parse as ul; print(ul.quote_plus(sys.stdin.read()))'";
nh-push = "/home/death916/Documents/nix-config/scripts/nh-push";
};
};
}

View file

@ -1,20 +1,27 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
# A wrapper for 'nh' that runs 'git push' on success.
# 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
# Run the 'nh' command with all arguments passed to the script.
# The flake path is hardcoded for convenience.
nh os switch "/home/death916/nixconfig#$@"
# 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/.."
# If the above command was successful, proceed to the next lines.
# --- 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 --flake "$REPO_ROOT#nixosConfigurations.$@"
# --- Git Push on Success ---
echo "NixOS rebuild successful. Pushing to remote..."
git -C "$REPO_ROOT" push
# Push the configuration to the git remote.
git -C /home/death916/nixconfig push
echo "Push complete."
echo "Push complete."