Replace cli flags with config file

This commit is contained in:
batteredbunny 2024-11-15 00:15:12 +02:00
parent 8a7e77d5f9
commit 5d07311353

View file

@ -11,6 +11,45 @@ let
mkPackageOption
mkIf
types;
configFile = pkgs.writeText "cross-seed-config.js" ''
module.exports = {
apiKey: ${if cfg.settings.apiKey != null then "'${cfg.settings.apiKey}'" else "undefined"},
torznab: ${if cfg.settings.torznab != [] then "[${lib.concatMapStringsSep ", " (x: "'${x}'") cfg.settings.torznab}]" else "[]"},
sonarr: ${if cfg.settings.sonarr != [] then "[${lib.concatMapStringsSep ", " (x: "'${x}'") cfg.settings.sonarr}]" else "undefined"},
radarr: ${if cfg.settings.radarr != [] then "[${lib.concatMapStringsSep ", " (x: "'${x}'") cfg.settings.radarr}]" else "undefined"},
host: ${if cfg.settings.host != null then "'${cfg.settings.host}'" else "undefined"},
port: ${toString cfg.settings.port},
notificationWebhookUrl: ${if cfg.settings.notificationWebhookUrl != null then "'${cfg.settings.notificationWebhookUrl}'" else "undefined"},
rtorrentRpcUrl: ${if cfg.settings.rtorrentRpcUrl != null then "'${cfg.settings.rtorrentRpcUrl}'" else "undefined"},
qbittorrentUrl: ${if cfg.settings.qbittorrentUrl != null then "'${cfg.settings.qbittorrentUrl}'" else "undefined"},
transmissionRpcUrl: ${if cfg.settings.transmissionRpcUrl != null then "'${cfg.settings.transmissionRpcUrl}'" else "undefined"},
delugeRpcUrl: ${if cfg.settings.delugeRpcUrl != null then "'${cfg.settings.delugeRpcUrl}'" else "undefined"},
delay: ${toString cfg.settings.delay},
dataDirs: ${if cfg.settings.dataDirs != [] then "[${lib.concatMapStringsSep ", " (x: "'${x}'") cfg.settings.dataDirs}]" else "[]"},
linkCategory: "${cfg.settings.linkCategory}",
linkDir: ${if cfg.settings.linkDir != null then "'${cfg.settings.linkDir}'" else "undefined"},
linkType: "${cfg.settings.linkType}",
flatLinking: ${if cfg.settings.flatLinking then "true" else "false"},
matchMode: "${cfg.settings.matchMode}",
maxDataDepth: ${toString cfg.settings.maxDataDepth},
torrentDir: "${cfg.settings.torrentDir}",
outputDir: "${cfg.settings.outputDir}",
includeSingleEpisodes: ${if cfg.settings.includeSingleEpisodes then "true" else "false"},
includeNonVideos: ${if cfg.settings.includeNonVideos then "true" else "false"},
fuzzySizeThreshold: ${toString cfg.settings.fuzzySizeThreshold},
excludeOlder: ${if cfg.settings.excludeOlder != null then "'${cfg.settings.excludeOlder}'" else "undefined"},
excludeRecentSearch: ${if cfg.settings.excludeRecentSearch != null then "'${cfg.settings.excludeRecentSearch}'" else "undefined"},
action: "${cfg.settings.action}",
duplicateCategories: ${if cfg.settings.duplicateCategories then "true" else "false"},
rssCadence: ${if cfg.settings.rssCadence != null then "'${cfg.settings.rssCadence}'" else "undefined"},
searchCadence: ${if cfg.settings.searchCadence != null then "'${cfg.settings.searchCadence}'" else "undefined"},
snatchTimeout: ${if cfg.settings.snatchTimeout != null then "'${cfg.settings.snatchTimeout}'" else "null"},
searchTimeout: ${if cfg.settings.searchTimeout != null then "'${cfg.settings.searchTimeout}'" else "null"},
searchLimit: ${toString cfg.settings.searchLimit},
blockList: ${if cfg.settings.blockList != [] then "[${lib.concatMapStringsSep ", " (x: "'${x}'") cfg.settings.blockList}]" else "undefined"},
};
'';
in
{
options.services.cross-seed = {
@ -293,6 +332,7 @@ in
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -p ${cfg.settings.outputDir}
ln -s ${configFile} /var/lib/cross-seed/config.js
'';
serviceConfig = {
@ -302,44 +342,7 @@ in
"CONFIG_DIR=${cfg.dataDir}"
];
WorkingDirectory = cfg.dataDir;
ExecStart = lib.concatStringsSep " " ([
"${lib.getExe cfg.package}"
"daemon"
"--match-mode ${cfg.settings.matchMode}"
"--link-category ${cfg.settings.linkCategory}"
"--link-type ${cfg.settings.linkType}"
"--max-data-depth ${toString cfg.settings.maxDataDepth}"
"--torrent-dir ${cfg.settings.torrentDir}"
"--output-dir ${cfg.settings.outputDir}"
"--delay ${toString cfg.settings.delay}"
"--snatch-timeout '${cfg.settings.snatchTimeout}'"
"--search-timeout '${cfg.settings.searchTimeout}'"
"--search-limit ${toString cfg.settings.searchLimit}"
]
++ lib.optionals (cfg.settings.torznab != [ ]) [ "--torznab ${lib.concatStringsSep " " cfg.settings.torznab}" ]
++ lib.optionals (cfg.settings.dataDirs != [ ]) [ "--data-dirs ${lib.concatStringsSep " " cfg.settings.dataDirs}" ]
++ lib.optionals (cfg.settings.linkDir != null) [ "--link-dir ${cfg.settings.linkDir}" ]
++ lib.optionals cfg.settings.flatLinking [ "--flat-linking" ]
++ lib.optionals cfg.settings.includeNonVideos [ "--include-non-videos" ]
++ lib.optionals cfg.settings.includeSingleEpisodes [ "--include-single-episodes" ]
++ lib.optionals (cfg.settings.excludeOlder != null) [ "--exclude-older ${cfg.settings.excludeOlder}" ]
++ lib.optionals (cfg.settings.excludeRecentSearch != null) [ "--exclude-recent-search ${cfg.settings.excludeRecentSearch}" ]
++ lib.optionals cfg.settings.verbose [ "--verbose" ]
++ lib.optionals (cfg.settings.rtorrentRpcUrl != null) [ "--rtorrent-rpc-url ${cfg.settings.rtorrentRpcUrl}" ]
++ lib.optionals (cfg.settings.qbittorrentUrl != null) [ "--qbittorrent-url ${cfg.settings.qbittorrentUrl}" ]
++ lib.optionals (cfg.settings.transmissionRpcUrl != null) [ "--transmission-rpc-url ${cfg.settings.transmissionRpcUrl}" ]
++ lib.optionals (cfg.settings.delugeRpcUrl != null) [ "--deluge-rpc-url ${cfg.settings.delugeRpcUrl}" ]
++ lib.optionals cfg.settings.duplicateCategories [ "--duplicate-categories" ]
++ lib.optionals (cfg.settings.notificationWebhookUrl != null) [ "--notification-webhook-url ${cfg.settings.notificationWebhookUrl}" ]
++ lib.optionals (cfg.settings.blockList != [ ]) [ "--block-list ${lib.concatStringsSep " " cfg.settings.blockList}" ]
++ lib.optionals (cfg.settings.sonarr != [ ]) [ "--sonarr ${lib.concatStringsSep " " cfg.settings.sonarr}" ]
++ lib.optionals (cfg.settings.radarr != [ ]) [ "--radarr ${lib.concatStringsSep " " cfg.settings.radarr}" ]
++ lib.optionals (cfg.settings.port != null) [ "--port ${toString cfg.settings.port}" ]
++ lib.optionals (cfg.settings.host != null) [ "--host ${cfg.settings.host}" ]
++ lib.optionals (cfg.settings.searchCadence != null) [ "--search-cadence '${cfg.settings.searchCadence}'" ]
++ lib.optionals (cfg.settings.rssCadence != null) [ "--rss-cadence '${cfg.settings.rssCadence}'" ]
++ lib.optionals (cfg.settings.apiKey != null) [ "--api-key ${cfg.settings.apiKey}" ]
);
ExecStart = "${lib.getExe cfg.package} daemon";
};
};
};