nixos-config/nixos/modules/castget.nix

102 lines
2.5 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
2023-08-03 11:50:39 +02:00
with types;
2019-10-24 02:20:38 +02:00
let
2024-03-03 09:59:17 +01:00
cfg = config.services.castget;
2021-11-01 09:20:42 +01:00
in
{
2019-10-24 02:20:38 +02:00
2024-03-03 09:59:17 +01:00
options.services.castget = {
enable = mkEnableOption "enable services.castget";
2019-10-24 02:20:38 +02:00
feeds = mkOption {
2023-08-03 11:50:39 +02:00
type = attrsOf (submodule {
options = {
url = mkOption {
type = str;
description = ''
url to the rss feed
'';
};
spool = mkOption {
type = path;
description = ''
download enclosures to this directory.
'';
2019-10-24 02:20:38 +02:00
};
2023-08-03 11:50:39 +02:00
};
});
2019-10-24 02:20:38 +02:00
description = ''
configurations for the cast
'';
};
user = mkOption {
2023-08-03 11:50:39 +02:00
type = str;
2019-10-24 02:20:38 +02:00
description = ''
user to run the systemd service as
'';
};
timerConfig = mkOption {
2023-08-03 11:50:39 +02:00
type = attrsOf str;
2019-12-20 05:54:26 +01:00
default = { OnCalendar = "daily"; };
2019-10-24 02:20:38 +02:00
example = {
OnCalendar = "00:05";
RandomizedDelaySec = "5h";
};
description = ''
When to run the polling script. See man systemd.timer for details.
2019-12-20 05:54:26 +01:00
'';
2019-10-24 02:20:38 +02:00
};
serviceName = mkOption {
2023-08-03 11:50:39 +02:00
type = str;
2019-10-24 02:20:38 +02:00
default = "castget";
description = ''
the name of the castget systemd service
'';
};
};
config = mkIf cfg.enable {
systemd.services."${cfg.serviceName}" = {
description = "castget polling service";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
restartIfChanged = false;
serviceConfig.User = cfg.user;
2021-11-01 09:20:42 +01:00
preStart =
let
2023-08-03 11:50:39 +02:00
mkSpools = mapAttrsToList (ignore: value: "mkdir -p \"${value.spool}\"") cfg.feeds;
2021-11-01 09:20:42 +01:00
in
concatStringsSep "\n" mkSpools;
script =
let
channels = mapAttrsToList (key: ignore: key) cfg.feeds;
castget = "${pkgs.castget}/bin/castget";
2019-10-24 02:20:38 +02:00
2021-11-01 09:20:42 +01:00
configurationFile =
let
configurations = mapAttrsToList
(key: value: ''
[${key}]
url=${value.url}
spool=${value.spool}
'')
cfg.feeds;
in
(pkgs.writeText "castget-configuration"
(concatStringsSep "" configurations));
in
(concatMapStringsSep "\n"
(channel: "${castget} --rcfile ${configurationFile} ${channel}")
channels);
2019-10-24 02:20:38 +02:00
};
systemd.timers."${cfg.serviceName}" = {
wantedBy = [ "timers.target" ];
timerConfig = cfg.timerConfig;
};
};
}