From d0c88d4e6a9d2cbb72d29cf0b7d61cf3fa74f114 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 5 Nov 2023 22:26:48 +0100 Subject: [PATCH] modules/nixfiles: add modules for system hydra sync --- modules/default.nix | 1 + .../nixfiles/system-auto-sync-to-hydra.nix | 29 +++++++++++++++++++ .../nixfiles/nixfiles-system-sync-to-hydra.sh | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 modules/nixfiles/system-auto-sync-to-hydra.nix diff --git a/modules/default.nix b/modules/default.nix index 8271876..c43aede 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -13,6 +13,7 @@ ./monitoring ./nginx-port-forward ./nixfiles + ./nixfiles/system-auto-sync-to-hydra.nix ./update-from-hydra ./wg-clerie ./wireguard-initrd diff --git a/modules/nixfiles/system-auto-sync-to-hydra.nix b/modules/nixfiles/system-auto-sync-to-hydra.nix new file mode 100644 index 0000000..3d41ea1 --- /dev/null +++ b/modules/nixfiles/system-auto-sync-to-hydra.nix @@ -0,0 +1,29 @@ +{ pkgs, lib, config, ... }: + +with lib; + +let + cfg = config.clerie.nixfiles.system-auto-sync-to-hydra; +in + +{ + options = { + clerie.nixfiles.system-auto-sync-to-hydra = { + enable = mkEnableOption "clerie nixfiles tools"; + allowReboot = mkOption { + type = types.bool; + default = false; + description = "Monitor NixOS"; + }; + }; + }; + config = mkIf cfg.enable { + systemd.services.nixfiles-system-auto-sync-to-hydra = { + serviceConfig = { + Type = "oneshot"; + ExecStart = pkgs.nixfiles-system-sync-to-hydra + "/bin/nixfiles-system-sync-to-hydra${optionalString cfg.allowReboot " --allow-reboot"}"; + }; + startAt = "*-*-* 06:47:00"; + }; + }; +} diff --git a/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh b/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh index 3111fe7..d3da0c0 100755 --- a/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh +++ b/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh @@ -17,7 +17,7 @@ while [[ $# -gt 0 ]]; do esac done -HYDRA_JOB_URL="https://hydra.clerie.de/job/nixfiles/nixfiles/nixosConfigurations.$(hostname)/latest-finished" +HYDRA_JOB_URL="https://hydra.clerie.de/job/nixfiles/nixfiles/nixosConfigurations.${HOSTNAME}/latest-finished" echo "Fetching job output from ${HYDRA_JOB_URL}" STORE_PATH="$(curl --fail -s -L -H "Accept: application/json" "${HYDRA_JOB_URL}" | jq -r ".buildoutputs.out.path")"