{ config, lib, pkgs, ... }: with lib; let cfg = config.services.joann-pupper-bot; in { options.services.joann-pupper-bot = { enable = mkEnableOption "Joann's Pupper Bot"; user = mkOption { type = types.str; default = "joann-pupper-bot"; example = "myuser"; description = "Which user should be running Joann's Pupper Bot"; }; group = mkOption { type = types.str; default = "joann-pupper-bot"; example = "mygroup"; description = "Which group should be running Joann's Pupper Bot"; }; stateDir = mkOption { type = types.str; default = "/var/lib/joann-pupper-bot"; description = "Which directory the bot should use for storage"; }; config.token = mkOption { type = types.str; description = "Bot token used for Telegram"; }; config.subreddits = mkOption { type = types.listOf types.str; description = "Which subreddits to draw images from"; default = ["rarepuppers"]; }; config.sendCron = mkOption { type = types.str; description = "cron-style string determining when images should be sent"; default = "*/30 8-21 * * *"; }; config.refreshCron = mkOption { type = types.str; description = "cron-style string determining when the bot polls Reddit for new images"; default = "*/15 * * * *"; }; config.recipients = mkOption { type = types.listOf types.int; description = "Telegram chat IDs for each of the image recipients"; }; }; config = mkIf cfg.enable { systemd.tmpfiles.rules = [ "d '${cfg.stateDir}' 0750 ${cfg.user} ${cfg.group} - -" ]; systemd.services.joann-pupper-bot = { description = "Joann's Pupper Bot"; wantedBy = [ "multi-user.target" ]; preStart = let yml = generators.toYAML {} cfg.config; configFile = pkgs.writeText "config.yaml" yml; in '' cp -f '${configFile}' '${cfg.stateDir}'/config.yaml ''; serviceConfig = { Type = "oneshot"; ExecStart = "/bin/sh -c :"; }; }; }; }