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"; }; 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.services.obsidian-tasks-reminder = { enable = true; description = "Obsidian Tasks Notifier"; wantedBy = ["network-online.target"]; after = ["network-online.target"]; serviceConfig = { ExecStart = "${app}/bin/obsidian-tasks-reminder"; User = cfg.user; }; }; }; }