autoupdate: unify scripts, hardcode hostname from config

This commit is contained in:
Sandro - 2022-06-12 16:24:44 +02:00
parent 03cbfb029f
commit 53fce8e2c7
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
1 changed files with 6 additions and 4 deletions

View File

@ -27,18 +27,20 @@
};
script = ''
OLD=$(readlink /run/current-system)
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/$(hostname)/latest | jq -r .buildoutputs.out.path)
echo Current system: $(basename $OLD)
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/${config.networking.hostName}/latest | jq -r .buildoutputs.out.path)
if [ -z "$NEW" ] || [ "$NEW" = "null" ]; then
echo "Unable to obtain updated system"
exit 1
fi
echo New system: $(basename $NEW)
if [ "$OLD" != "$NEW" ]; then
echo "New system available: $NEW"
echo "Fetching new system built by https://hydra.hq.c3d2.de/jobset/c3d2/nix-config"
# this should fetch the new system from the binary cache
nix copy --from https://nix-serve.hq.c3d2.de "$NEW"
if [ -e "$NEW/etc/systemd/system/autoupdate.timer" ]; then
# switch to the new system
echo "Switch to the new system..."
"$NEW/bin/switch-to-configuration" switch
else
echo "New system is not yet autoupdate-enabled. Refusing to switch into a dead end."
@ -76,7 +78,7 @@
OLD=$(readlink /run/current-system)
echo Current system: $(basename $OLD)
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/$(hostname)/latest | ${pkgs.jq}/bin/jq -r .buildoutputs.out.path)
NEW=$(curl -sLH "Accept: application/json" https://hydra.hq.c3d2.de/job/c3d2/nix-config/${config.networking.hostName}/latest | ${pkgs.jq}/bin/jq -r .buildoutputs.out.path)
if [ -z "$NEW" ] || [ "$NEW" = "null" ]; then
echo "Unable to obtain updated system"
exit 1