use hydra’s latestbuild api to find latest build for a job
All checks were successful
Hydra nixosConfigurations.container-default-x86_64-linux Hydra build #22915 of nixos-config:pr618:nixosConfigurations.container-default-x86_64-linux
Hydra checks.x86_64-linux.containers-default Hydra build #22912 of nixos-config:pr618:checks.x86_64-linux.containers-default
Hydra nixosConfigurations.container-default-aarch64-linux Hydra build #22913 of nixos-config:pr618:nixosConfigurations.container-default-aarch64-linux
Hydra nixosConfigurations.container-default-riscv64-linux Hydra build #22914 of nixos-config:pr618:nixosConfigurations.container-default-riscv64-linux
Hydra nixosConfigurations.not522 Hydra build #22916 of nixos-config:pr618:nixosConfigurations.not522
Hydra nixosConfigurations.not522-installer Hydra build #22917 of nixos-config:pr618:nixosConfigurations.not522-installer

This commit is contained in:
Charlotte 🦝 Delenk 2024-11-02 08:13:30 +01:00
parent 31d5bce7b8
commit fcc5491f8d

View file

@ -3,8 +3,10 @@
pkgs,
lib,
...
}:
with lib; {
}: let
cfg = config.nix.auto-update;
in
with lib; {
options.nix.auto-update = {
enable = mkEnableOption "enable automatic updates";
reboot = mkEnableOption "Reboot if kernel change";
@ -13,14 +15,19 @@ with lib; {
description = "Location of hydra server";
default = "https://hydra.chir.rs";
};
source = mkOption {
project = mkOption {
type = types.str;
description = "Source to update from";
default = "${config.nix.auto-update.hydraServer}/jobset/nixos-config/pr618/evals";
description = "Project name to use";
default = "nixos-config";
};
attr = mkOption {
jobset = mkOption {
type = types.str;
description = "Attribute to update from";
description = "Jobset name to use";
default = "pr618";
};
job = mkOption {
type = types.str;
description = "Job name to use";
default = "nixosConfigurations.${config.networking.hostName}";
};
};
@ -40,11 +47,8 @@ with lib; {
script = ''
#!${pkgs.bash}/bin/bash
set -euxo pipefail
builds=$(${pkgs.curl}/bin/curl -H "accept: application/json" ${config.nix.auto-update.source} | ${pkgs.jq}/bin/jq -r '.evals[0].builds[]')
for build in $builds; do
build=$(${pkgs.curl}/bin/curl -H "accept: application/json" ${cfg.hydraServer}/api/latestbuilds -d "nr=10" -d "project=${cfg.project}" | ${pkgs.jq}/bin/jq -r '[.[]|select(.buildstatus==0)][0]][0].id')
doc=$(${pkgs.curl}/bin/curl -H "accept: application/json" ${config.nix.auto-update.hydraServer}/build/$build)
jobname=$(echo $doc | ${pkgs.jq}/bin/jq -r '.job')
if [ "$jobname" = "${config.nix.auto-update.attr}" ]; then
drvname=$(echo $doc | ${pkgs.jq}/bin/jq -r '.drvpath')
output=$(${pkgs.nix}/bin/nix-store -r $drvname)
${pkgs.nix}/bin/nix-env -p /nix/var/nix/profiles/system --set $output
@ -65,8 +69,6 @@ with lib; {
$output/bin/switch-to-configuration switch
''
}
fi
done
'';
};
@ -88,4 +90,4 @@ with lib; {
message = "Auto updating will only work when nix itself is enabled.";
}
];
}
}