aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-06-08 21:38:37 +0530
committerAkshay Nair <phenax5@gmail.com>2025-06-10 16:18:26 +0530
commit3dd4a84724190d318a960cec67077d91f4556910 (patch)
tree00aa5f25e13efe38881414844bdf6e664304195a
parent6fa61afb16715aabef42fdad1ef5633563e6519c (diff)
downloadhomeserver-nixos-config-3dd4a84724190d318a960cec67077d91f4556910.tar.gz
homeserver-nixos-config-3dd4a84724190d318a960cec67077d91f4556910.zip
More power to the build script
-rwxr-xr-xbuild.sh45
1 files changed, 39 insertions, 6 deletions
diff --git a/build.sh b/build.sh
index c2229a8..93ae9c0 100755
--- a/build.sh
+++ b/build.sh
@@ -1,20 +1,53 @@
#!/usr/bin/env sh
set -euo pipefail
-SSH_TARGET="bacchus@192.168.0.117"
+getconfig() {
+ nix eval --impure --expr "(import ./config.private.nix)$@" | jq -r
+}
+
+SSH_HOST="$(getconfig .ssh.host)"
+SSH_PORT="$(getconfig .ssh.port)"
+SSH_TARGET="bacchus@$SSH_HOST"
+SCRIPT_PATH="$(readlink -f "$0")"
+
+run_ssh() { ssh -t "$SSH_TARGET" -p "$SSH_PORT" "$@"; }
+copy() { rsync -r -e "ssh -p $SSH_PORT" "$@"; }
+waittostart() {
+ echo "Waiting...";
+ until timeout 2 nc -z "$SSH_HOST" "$SSH_PORT" 2> /dev/null; do
+ echo -n '.';
+ sleep 2
+ done;
+ echo -e "\nReady to connect";
+}
config_sync() {
- rsync -r "$SSH_TARGET:~/nixos/flake.lock" .
- rsync -r . "$SSH_TARGET:~/nixos"
- # ssh "$SSH_TARGET" sh -c "nixos-rebuild build --flake 'path:/home/bacchus/nixos#bacchus'"
+ copy "$SSH_TARGET:~/nixos/flake.lock" .;
+ copy . "$SSH_TARGET:~/nixos";
}
-run_ssh() { ssh -t "$SSH_TARGET" "$@"; }
+rebuild() {
+ run_ssh sudo nixos-rebuild switch --flake 'path:/home/bacchus/nixos#bacchus';
+}
+
+restart() { run_ssh sudo systemctl reboot; }
+
+chaincmds() {
+ for arg in "$@"; do
+ echo "Running: $arg...";
+ "$SCRIPT_PATH" "$arg";
+ done
+}
cmd="$1"; shift;
case "$cmd" in
sync) config_sync ;;
run) run_ssh "$@" ;;
- *) echo "foo" && exit 1 ;;
+ build) rebuild ;;
+ restart) restart && sleep 3 && waittostart ;;
+ wait) waittostart ;;
+ clean) run_ssh sudo nix-collect-garbage -d ;;
+ _) chaincmds "$@" ;;
+ *) echo "Invalid cmd: $1" && exit 1 ;;
esac