{ config, pkgs, lib, utils, ... }: let cfg = config.services.abs-podcast-autoplaylist; enabledAttrs = lib.filterAttrs (_name: { enable, ... }: enable) cfg; in { options = { services.abs-podcast-autoplaylist = lib.mkOption { default = {}; type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: { options = { enable = lib.mkEnableOption "this instance of abs-podcast-autoplaylist" // { default = true; }; cron = lib.mkOption { type = lib.types.str; default = "*-*-* *:00/30:00"; }; configSecret = lib.mkOption { type = lib.types.str; default = "abs-podcast-autoplaylist-${name}.toml"; }; }; })); }; }; config = lib.mkIf (enabledAttrs != {}) { systemd.services = { "abs-podcast-autoplaylist@" = { serviceConfig = { WorkingDirectory = "%d"; DynamicUser = true; ProtectHome = true; PrivateTmp = true; PrivateDevices = true; Type = "oneshot"; ExecStart = "${lib.getExe pkgs.abs-podcast-autoplaylist} %I.toml"; }; }; } // lib.mapAttrs' (name: { configSecret, ... }: lib.nameValuePair "abs-podcast-autoplaylist@${utils.escapeSystemdPath name}" { overrideStrategy = "asDropin"; serviceConfig = { LoadCredential = "${name}.toml:${config.sops.secrets.${configSecret}.path}"; }; }) enabledAttrs; systemd.timers = lib.mapAttrs' (name: { cron, ... }: lib.nameValuePair "abs-podcast-autoplaylist@${utils.escapeSystemdPath name}" { wantedBy = [ "timers.target" ]; timerConfig.OnCalendar = cron; }) enabledAttrs; }; }