aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-30 15:18:51 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-30 15:18:51 +0200
commit484673d59bdd15fb10bdc366f5d8b15fee596b8e (patch)
treee8aa7e9ea8081275790daf8eeab827852e30d509 /scripts
parentmodules: Use namespaces (diff)
downloadnixos-server-484673d59bdd15fb10bdc366f5d8b15fee596b8e.zip
scripts/{build.sh,update_host.sh}: Make smarter
Diffstat (limited to '')
-rwxr-xr-xscripts/build.sh33
-rw-r--r--scripts/update_hosts.remote19
-rwxr-xr-xscripts/update_hosts.sh75
3 files changed, 114 insertions, 13 deletions
diff --git a/scripts/build.sh b/scripts/build.sh
index a3ff064..df55ac5 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -1,5 +1,38 @@
#! /usr/bin/env sh
+set -eu
+
+wrong_arg=false
+use_dirty=false
+
+for arg in "$@"; do
+ case "$arg" in
+ --dirty)
+ use_dirty=true
+ ;;
+ *)
+ echo "arg '$arg' is not known."
+ wrong_arg=true
+ ;;
+ esac
+done
+
+if [ "$wrong_arg" = true ]; then
+ exit 2
+fi
+
+if [ "$use_dirty" = "false" ]; then
+ tmp="$(mktemp -d -t "server_build_script_XXXXX")"
+ trap 'rm -r "$tmp"' EXIT
+
+ git archive --format=tar.gz HEAD | {
+ cd "$tmp"
+ tar -xz
+ }
+
+ cd "$tmp"
+fi
+
for host in "server2" "server3"; do
nix build ".#nixosConfigurations.$host.config.system.build.toplevel" --print-out-paths --no-link --option max-jobs 1
done
diff --git a/scripts/update_hosts.remote b/scripts/update_hosts.remote
index 249b24e..7385129 100644
--- a/scripts/update_hosts.remote
+++ b/scripts/update_hosts.remote
@@ -16,6 +16,7 @@ PATH_add() {
}
branch="$1"
+flake_path="${2-""}"
# We don't have access to git by default, so evaluate it here
PATH_add git
@@ -29,13 +30,19 @@ PATH_add lixPackageSets.latest.lix
PATH_add python3
PATH_add nixos-rebuild
-set -x
-cd /etc/nixos
+if [ -z "$flake_path" ]; then
+ set -x
+ cd /etc/nixos
-sudo git fetch --all --prune
-sudo git switch "$branch"
-sudo git pull --rebase
+ sudo git fetch --all --prune
+ sudo git switch "$branch"
+ sudo git pull --rebase
-PYTHONNOUSERSITE='true' sudo --preserve-env=PATH --preserve-env=PYTHONNOUSERSITE ".nixos-rebuild-wrapped" --no-reexec boot
+ flake_path="git+file:/etc/nixos/"
+fi
+
+# we use the unwrapped one, to make sure that we are really using lix (otherwise it might
+# be wrapped with cppnix).
+PYTHONNOUSERSITE='true' sudo --preserve-env=PATH --preserve-env=PYTHONNOUSERSITE ".nixos-rebuild-wrapped" --flake "$flake_path" --no-reexec boot
sudo reboot
diff --git a/scripts/update_hosts.sh b/scripts/update_hosts.sh
index cc459ed..94003b8 100755
--- a/scripts/update_hosts.sh
+++ b/scripts/update_hosts.sh
@@ -3,21 +3,82 @@ set -e
base_dir="$(git rev-parse --show-toplevel)"
-user="${1-$USER}"
-hosts="${2-server2 server3}"
-branch="${3-main}"
+user="$USER"
+set_hosts=""
+branch="main"
+direct=false
+
+while [ "$#" -ne 0 ]; do
+ case "$1" in
+ --user)
+ shift 1
+ user="$1"
+ ;;
+ --host)
+ shift 1
+ set_hosts="$set_hosts $1"
+ ;;
+ --hosts)
+ shift 1
+ if [ -n "$set_hosts" ]; then
+ echo "Warning: --hosts overrides --host"
+ fi
+ set_hosts="$1"
+ ;;
+ --branch)
+ shift 1
+ branch="$1"
+ ;;
+ --direct)
+ direct=true
+ ;;
+ *)
+ echo "Arg '$1' not known."
+ exit 2
+ ;;
+ esac
+ shift 1
+done
+
+hosts="${set_hosts-"server2 server3"}"
+
+echo "update_hosts.sh --user '$user' --hosts '$hosts' --branch '$branch' --direct '$direct'"
for host in $hosts; do
echo "Updating '$user@$host.vhack.eu' ..."
- printf "Copying closure ..\n"
- nix copy --substitute-on-destination --to "ssh://$user@$host.vhack.eu" ".#nixosConfigurations.$host.config.system.build.toplevel"
-
printf "Deploying remote side script ..\n"
scp "$base_dir/scripts/update_hosts.remote" "$user@$host.vhack.eu:update_host.remote"
+ set -x
+
+ flake_path=""
+ if [ "$direct" = true ]; then
+ printf "Deploying git config ..\n"
+
+ flake_path="path:$(git archive --format=tar.gz HEAD |
+ ssh "$user@$host.vhack.eu" \
+ 'flake_path=$(mktemp -d -t update_hosts_XXXXX); cd $flake_path && tar -xz; echo $flake_path')"
+
+ fi
+
+ tmp="$(mktemp -d -t "server_build_script_XXXXX")"
+ trap 'rm -r "$tmp"' EXIT
+ if [ "$direct" = true ]; then
+ git archive --format=tar.gz HEAD | {
+ cd "$tmp"
+ tar -xz
+ }
+ else
+ git clone "git.foss-syndicate.org" --branch="$branch" "$tmp"
+ fi
+ cd "$tmp"
+
+ printf "Copying closure ..\n"
+ nix copy --substitute-on-destination --to "ssh://$user@$host.vhack.eu" ".#nixosConfigurations.$host.config.system.build.toplevel"
+
printf "Executing remote side script ..\n"
- ssh -t "$user@$host.vhack.eu" "chmod +x update_host.remote; ./update_host.remote '$branch'"
+ ssh -t "$user@$host.vhack.eu" "chmod +x update_host.remote; ./update_host.remote '$branch' '$flake_path'"
done
# Give the servers some time to reboot