From cee54def460fcde7a30df1c0437c04b78a4ad1ac Mon Sep 17 00:00:00 2001 From: death916 Date: Mon, 30 Jun 2025 15:16:38 -0700 Subject: [PATCH] nh script update --- home-manager/death916-homelab.nix | 4 ++++ home-manager/home.nix | 1 + scripts/nh-push | 29 ++++++++++++++++++----------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/home-manager/death916-homelab.nix b/home-manager/death916-homelab.nix index 393fbf2..f5ca547 100644 --- a/home-manager/death916-homelab.nix +++ b/home-manager/death916-homelab.nix @@ -22,4 +22,8 @@ systemctl-tui gemini-cli ]; + + programs.bash.shellAliases = { + nh-push = "/home/death916/nixconfig/scripts/nh-push"; + }; } diff --git a/home-manager/home.nix b/home-manager/home.nix index 69ac08c..d0076b3 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -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"; }; }; } diff --git a/scripts/nh-push b/scripts/nh-push index d46c44b..7239686 100755 --- a/scripts/nh-push +++ b/scripts/nh-push @@ -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." \ No newline at end of file