From 50fa917e7e2faf2afa0d97748ede036bdb7a769a Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Thu, 18 Dec 2025 07:11:44 -0500 Subject: nix/module: support restart timer --- nix/module.nix | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nix/module.nix b/nix/module.nix index 5b59937..09857a2 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -47,6 +47,12 @@ in { default = null; }; + restartTimer = mkOption { + description = "restart on timer"; + type = nullOr str; + default = null; + }; + postgres = mkOption { description = "local postgres server with automatic setup"; @@ -155,6 +161,32 @@ in { }; }; + systemd.timers.thulani-restart = lib.mkIf (cfg.restartTimer != null) { + wantedBy = ["timers.target"]; + + timerConfig = { + OnCalendar = cfg.restartTimer; + Unit = "thulani-restart.service"; + }; + }; + + systemd.services.thulani-restart = lib.mkIf (cfg.restartTimer != null) { + description = "restart thulani bot"; + + serviceConfig = { + Type = "oneshot"; + }; + + script = '' + set -euo pipefail + + if systemctl is-active thulani.service; then + exec systemctl restart --no-block thulani.service + fi + ''; + }; + + services.postgresql = lib.mkIf cfg.postgres.enable { enable = true; -- cgit v1.3.1