From 8156997b0c96a5918100b0739bceebd740d336e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Sun, 9 Jul 2023 18:17:46 +0100 Subject: [PATCH] fix update script for real --- config/nix.nix | 27 ++++++++++++++++++++++++++- config/nixos-8gb-fsn1-1.nix | 23 ++++++++++++++++++++++- extra/update-reboot.sh | 25 ------------------------- extra/update.sh | 18 ------------------ 4 files changed, 48 insertions(+), 45 deletions(-) delete mode 100755 extra/update-reboot.sh delete mode 100755 extra/update.sh diff --git a/config/nix.nix b/config/nix.nix index 2388231a..3fbe291d 100644 --- a/config/nix.nix +++ b/config/nix.nix @@ -133,7 +133,32 @@ curl ]; - script = lib.mkDefault "${../extra/update-reboot.sh}"; + script = lib.mkDefault '' + #!${pkgs.bash}/bin/bash + + set -ex + + builds=$(${pkgs.curl}/bin/curl -H 'accept: application/json' https://hydra.int.chir.rs/jobset/nixos-config/nixos-config/evals | ${pkgs.jq}/bin/jq -r '.evals[0].builds[]') + + for build in $builds; do + doc=$(${pkgs.curl}/bin/curl -H 'accept: application/json' https://hydra.int.chir.rs/build/$build) + jobname=$(echo $doc | ${pkgs.jq}/bin/jq -r '.job') + if [ "$jobname" = "${config.networking.hostName}.${system}" ]; then + drvname=$(echo $doc | ${pkgs.jq}/bin/jq -r '.drvpath') + output=$(${pkgs.nix}/bin/nix-store -r $drvname) + $output/bin/switch-to-configuration boot + booted="$(${pkgs.coreutils}/bin/readlink /run/booted-system/{initrd,kernel,kernel-modules})" + built="$(${pkgs.coreutils}/bin/readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" + if [ "$booted" = "$built" ]; then + $output/bin/switch-to-configuration switch + else + ${pkgs.systemd}/bin/shutdown -r +1 + fi + exit + fi + done + + ''; after = ["network-online.target"]; wants = ["network-online.target"]; }; diff --git a/config/nixos-8gb-fsn1-1.nix b/config/nixos-8gb-fsn1-1.nix index 78eb71b1..386693d8 100644 --- a/config/nixos-8gb-fsn1-1.nix +++ b/config/nixos-8gb-fsn1-1.nix @@ -1,6 +1,9 @@ { lib, modulesPath, + pkgs, + config, + system, ... } @ args: { networking.hostName = "nixos-8gb-fsn1-1"; @@ -206,5 +209,23 @@ services.resolved.enable = false; services.bind.forwarders = lib.mkForce []; services.tailscale.useRoutingFeatures = "server"; - systemd.services.nixos-upgrade.script = lib.mkForce "${../extra/update.sh}"; + systemd.services.nixos-upgrade.script = lib.mkForce '' + #!${pkgs.bash}/bin/bash + + set -ex + + builds=$(${pkgs.curl}/bin/curl -H 'accept: application/json' https://hydra.int.chir.rs/jobset/nixos-config/nixos-config/evals | ${pkgs.jq}/bin/jq -r '.evals[0].builds[]') + + for build in $builds; do + doc=$(${pkgs.curl}/bin/curl -H 'accept: application/json' https://hydra.int.chir.rs/build/$build) + jobname=$(echo $doc | ${pkgs.jq}/bin/jq -r '.job') + if [ "$jobname" = "${config.networking.hostName}.${system}" ]; then + drvname=$(echo $doc | ${pkgs.jq}/bin/jq -r '.drvpath') + output=$(${pkgs.nix}/bin/nix-store -r $drvname) + $output/bin/switch-to-configuration switch + exit + fi + done + + ''; } diff --git a/extra/update-reboot.sh b/extra/update-reboot.sh deleted file mode 100755 index 7124c85e..00000000 --- a/extra/update-reboot.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p bash curl jq nix - -set -ex - -builds=$(curl -H 'accept: application/json' https://hydra.int.chir.rs/jobset/nixos-config/nixos-config/evals | jq -r '.evals[0].builds[]') - -for build in $builds; do - doc=$(curl -H 'accept: application/json' https://hydra.int.chir.rs/build/$build) - system=$(echo $doc | jq -r '.system') - jobname=$(echo $doc | jq -r '.job') - if [ "$jobname" = "$(hostname).$system" ]; then - drvname=$(echo $doc | jq -r '.drvpath') - output=$(nix-store -r $drvname) - $output/bin/switch-to-configuration boot - booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})" - built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" - if [ "${booted}" = "${built}" ]; then - $output/bin/switch-to-configuration switch - else - shutdown -r +1 - fi - exit - fi -done diff --git a/extra/update.sh b/extra/update.sh deleted file mode 100755 index 8e6b27af..00000000 --- a/extra/update.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p bash curl jq nix - -set -ex - -builds=$(curl -H 'accept: application/json' https://hydra.int.chir.rs/jobset/nixos-config/nixos-config/evals | jq -r '.evals[0].builds[]') - -for build in $builds; do - doc=$(curl -H 'accept: application/json' https://hydra.int.chir.rs/build/$build) - system=$(echo $doc | jq -r '.system') - jobname=$(echo $doc | jq -r '.job') - if [ "$jobname" = "$(hostname).$system" ]; then - drvname=$(echo $doc | jq -r '.drvpath') - output=$(nix-store -r $drvname) - $output/bin/switch-to-configuration switch - exit - fi -done