From 81cc664d4250189c9026edfb042e24c6806448ee Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 10 May 2025 12:53:58 +0200 Subject: abs-podcast-autoplaylist --- modules/abs-podcast-autoplaylist.nix | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/abs-podcast-autoplaylist.nix (limited to 'modules/abs-podcast-autoplaylist.nix') diff --git a/modules/abs-podcast-autoplaylist.nix b/modules/abs-podcast-autoplaylist.nix new file mode 100644 index 00000000..2532cfc3 --- /dev/null +++ b/modules/abs-podcast-autoplaylist.nix @@ -0,0 +1,54 @@ +{ 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; + }; +} -- cgit v1.2.3