Merge pull request 'fix update script for real' (#138) from actually-fix-update-script into main
Reviewed-on: #138
This commit is contained in:
commit
832214e8d6
4 changed files with 48 additions and 45 deletions
|
@ -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"];
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue