WIP: rewrite config #618

Draft
darkkirb wants to merge 392 commits from rewrite into main
Showing only changes of commit fcc5491f8d - Show all commits

View file

@ -3,7 +3,9 @@
pkgs,
lib,
...
}:
}: let
cfg = config.nix.auto-update;
in
with lib; {
options.nix.auto-update = {
enable = mkEnableOption "enable automatic updates";
@ -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
'';
};