From ccb433ae9a1f8b5f2fcaf44b2fd54db7a804cb2a Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 31 Oct 2023 16:20:21 +0100 Subject: [PATCH] Use systemd.timer instead of cron --- modules/push-notifications.nix | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/push-notifications.nix b/modules/push-notifications.nix index c5d7306..80aab39 100644 --- a/modules/push-notifications.nix +++ b/modules/push-notifications.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, pkgs, ... }: { services.ntfy-sh = { @@ -19,10 +19,24 @@ users.groups."ntfy" = { }; - services.cron = { - enable = true; - systemCronJobs = [ - "0 9,12,22 * * * ntfy . ${../scripts/push-room-humidity.sh} >> /tmp/cron-ntfy.log 2>&1" - ]; + systemd.services."send-room-humidity" = { + path = [ pkgs.curl ]; + script = '' + set -eu + ${../scripts/push-room-humidity.sh} + ''; + serviceConfig = { + Type = "oneshot"; + User = "ntfy"; + }; + }; + + systemd.timers."send-room-humidity" = { + wantedBy = [ "timers.target" ]; + after = [ "network-online.target" ]; + timerConfig = { + OnCalendar = [ "*-*-* 8:00" "*-*-* 22:00" ]; + Unit = "send-room-humidity.service"; + }; }; }