self: { config, pkgs, lib, system, ... }: let cfg = config.services.obsidian-tasks-reminder; appConfig = (pkgs.formats.yaml {}).generate "obsidian-tasks-reminder.config.yaml" cfg.config; app = pkgs.writeShellApplication { name = "obsidian-tasks-reminder"; runtimeInputs = [self.packages.${system}.default]; text = '' obsidian-tasks-reminder -c "${appConfig}" "$@"; ''; }; in with lib; { options.services.obsidian-tasks-reminder = { enable = mkEnableOption "obsidian-tasks-reminder"; user = mkOption { type = types.str; description = "User which will be used to run the app"; example = "root"; default = "root"; }; scanTimer = mkOption { type = types.str; description = "The systemd's timer interval when the app will be performing the scan for new tasks"; example = "*-*-* *:00"; default = "*-*-* *:10"; }; config = mkOption { type = types.attrs; description = "The obsidian-tasks-reminder config which will be eventually converted to yaml"; example = { sources = ["/var/lib/obsidian-data"]; query = "$. iority > MEDIUM && $.status !== 'x'"; mapper = "{ text: $.label, title: 'Task reminder' }"; databaseFile = "/tmp/obsidian-tasks-reminder.json"; backend.ntfy = { enable = true; url = "ntfy.sh"; token = "$__file:/etc/tokens/ntfy-sh.key"; topic = "obsidian"; }; }; }; }; config = mkIf cfg.enable { environment.systemPackages = [app]; systemd.timers.obsidian-tasks-reminder-scanner = { description = "Scan for new Obsidian tasks"; wantedBy = ["timers.target"]; timerConfig = { OnCalendar = cfg.scanTimer; Unit = "obsidian-tasks-reminder-scanner.service"; }; }; systemd.timers.obsidian-tasks-reminder = { description = "Notify about Obsidian tasks"; wantedBy = ["timers.target"]; timerConfig = { OnCalendar = "*-*-* *:*:00"; Unit = "obsidian-tasks-reminder.service"; }; }; systemd.services.obsidian-tasks-reminder-scanner = { description = "Scan for new Obsidian tasks"; serviceConfig = { Type = "oneshot"; User = cfg.user; }; script = "${app}/bin/obsidian-tasks-reminder -s"; }; systemd.services.obsidian-tasks-reminder = { description = "Notify about Obsidian tasks"; serviceConfig = { Type = "oneshot"; User = cfg.user; }; script = "${app}/bin/obsidian-tasks-reminder -n"; }; }; }