nixos-config/nixos/modules/services/castget.nix

98 lines
2.5 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.custom.services.castget;
in {
options.custom.services.castget = {
enable = mkEnableOption "enable custom.services.castget";
feeds = mkOption {
2019-12-20 05:54:26 +01:00
type = with types;
attrsOf (submodule {
options = {
url = mkOption {
type = with types; str;
description = ''
url to the rss feed
'';
};
spool = mkOption {
type = with types; path;
description = ''
download enclosures to this directory.
'';
};
2019-10-24 02:20:38 +02:00
};
2019-12-20 05:54:26 +01:00
});
2019-10-24 02:20:38 +02:00
description = ''
configurations for the cast
'';
};
user = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; string;
2019-10-24 02:20:38 +02:00
description = ''
user to run the systemd service as
'';
};
timerConfig = mkOption {
type = with types; 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 {
2019-12-20 05:54:26 +01:00
type = with types; string;
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;
2019-12-20 05:54:26 +01:00
preStart = let
mkSpools =
mapAttrsToList (ignore: value: "mkdir -p ${value.spool}") cfg.feeds;
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
2019-12-20 05:54:26 +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;
};
};
}