diff options
| author | Nathan Perry <np@npry.dev> | 2025-12-18 07:11:44 -0500 |
|---|---|---|
| committer | Nathan Perry <np@npry.dev> | 2025-12-18 07:46:10 -0500 |
| commit | 50fa917e7e2faf2afa0d97748ede036bdb7a769a (patch) | |
| tree | 82c60148163452d2921d8cb6503407534569fd82 /nix | |
| parent | df320f78fb5fa740041f87cc1d2e8faa086ff95c (diff) | |
nix/module: support restart timer
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/module.nix | 32 |
1 files changed, 32 insertions, 0 deletions
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; |
