2023-11-05 22:26:48 +01:00
|
|
|
{ pkgs, lib, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2024-03-14 20:30:37 +01:00
|
|
|
cfg = config.clerie.system-auto-upgrade;
|
2023-11-05 22:26:48 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
2024-03-14 20:30:37 +01:00
|
|
|
clerie.system-auto-upgrade = {
|
|
|
|
enable = mkEnableOption "clerie system upgrade";
|
2023-11-05 22:26:48 +01:00
|
|
|
allowReboot = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Monitor NixOS";
|
|
|
|
};
|
2023-12-15 20:20:53 +01:00
|
|
|
autoUpgrade = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Automatically check and install upgrades";
|
|
|
|
};
|
2023-12-15 18:58:01 +01:00
|
|
|
startAt = mkOption {
|
2024-03-24 13:18:27 +01:00
|
|
|
type = with types; nullOr str;
|
2023-12-15 18:58:01 +01:00
|
|
|
default = null;
|
|
|
|
description = "Systemd time string for starting the unit";
|
|
|
|
};
|
2023-11-05 22:26:48 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
2024-03-14 20:30:37 +01:00
|
|
|
systemd.services.clerie-system-auto-upgrade = {
|
2024-03-19 19:41:22 +01:00
|
|
|
requires = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
|
2023-12-03 11:28:41 +01:00
|
|
|
# Make sure this unit does not stop themself while upgrading
|
|
|
|
restartIfChanged = false;
|
|
|
|
unitConfig.X-StopOnRemoval = false;
|
|
|
|
|
2023-11-05 22:26:48 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
2024-03-17 15:50:49 +01:00
|
|
|
ExecStart = pkgs.clerie-system-upgrade + "/bin/clerie-system-upgrade --no-confirm${optionalString cfg.allowReboot " --allow-reboot"}${optionalString (config.clerie.monitoring.enable) " --node-exporter-metrics-path /var/lib/prometheus-node-exporter/textfiles/clerie-system-upgrade.prom"}";
|
2023-11-05 22:26:48 +01:00
|
|
|
};
|
2023-12-03 14:46:51 +01:00
|
|
|
};
|
2024-03-14 20:30:37 +01:00
|
|
|
systemd.timers.clerie-system-auto-upgrade = mkIf cfg.autoUpgrade {
|
2023-12-03 14:46:51 +01:00
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
2023-12-15 18:58:01 +01:00
|
|
|
OnCalendar = if cfg.startAt == null then "*-*-* 05:37:00" else cfg.startAt;
|
|
|
|
RandomizedDelaySec = if cfg.startAt == null then "2h" else "10m";
|
2023-12-03 14:46:51 +01:00
|
|
|
};
|
2024-03-19 19:41:22 +01:00
|
|
|
requires = [ "network-online.target" ];
|
2023-12-03 14:46:51 +01:00
|
|
|
after = [ "network-online.target" ];
|
2023-11-05 22:26:48 +01:00
|
|
|
};
|
2023-12-15 20:20:53 +01:00
|
|
|
environment.systemPackages = with pkgs; [
|
2024-03-17 15:50:49 +01:00
|
|
|
clerie-system-upgrade
|
2023-12-15 20:20:53 +01:00
|
|
|
];
|
2023-11-05 22:26:48 +01:00
|
|
|
};
|
|
|
|
}
|