2024-08-21 10:12:50 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2022-04-03 02:18:22 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.yt-dlp;
|
|
|
|
|
2022-08-11 01:43:17 +00:00
|
|
|
serviceLevelArgs = lib.escapeShellArgs cfg.extraArgs;
|
|
|
|
|
2022-09-11 11:48:33 +00:00
|
|
|
jobUnitName = name: "yt-dlp-archive-service-${name}";
|
|
|
|
|
2024-08-21 10:12:50 +00:00
|
|
|
jobType = { name, config, ... }: {
|
2022-04-03 02:18:22 +00:00
|
|
|
options = {
|
|
|
|
urls = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
2023-07-27 03:13:39 +00:00
|
|
|
A list of URLs to be downloaded to {command}`yt-dlp`. Please
|
|
|
|
see the list of extractors with `--list-extractors`.
|
2022-04-03 02:18:22 +00:00
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
"https://www.youtube.com/c/ronillust"
|
|
|
|
"https://www.youtube.com/c/Jazza"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
startAt = lib.mkOption {
|
|
|
|
type = with lib.types; str;
|
|
|
|
description = ''
|
2022-07-21 01:54:00 +00:00
|
|
|
Indicates how frequent the download will occur. The given schedule
|
|
|
|
should follow the format as described from
|
2023-07-27 03:13:39 +00:00
|
|
|
{manpage}`systemd.time(5)`.
|
2022-04-03 02:18:22 +00:00
|
|
|
'';
|
|
|
|
default = "daily";
|
|
|
|
example = "*-*-3/4";
|
|
|
|
};
|
|
|
|
|
2024-08-21 10:12:50 +00:00
|
|
|
extraArgs = options.services.yt-dlp.extraArgs // {
|
|
|
|
default = cfg.extraArgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
archivePath = options.services.yt-dlp.archivePath // {
|
|
|
|
default = cfg.archivePath;
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-11-19 03:05:31 +00:00
|
|
|
in
|
|
|
|
{
|
2022-04-03 02:18:22 +00:00
|
|
|
options.services.yt-dlp = {
|
|
|
|
enable = lib.mkEnableOption "archiving service with yt-dlp";
|
|
|
|
|
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
description =
|
2023-07-27 03:13:39 +00:00
|
|
|
"The derivation that contains {command}`yt-dlp` binary.";
|
2022-04-03 02:18:22 +00:00
|
|
|
default = pkgs.yt-dlp;
|
|
|
|
defaultText = lib.literalExpression "pkgs.yt-dlp";
|
|
|
|
example = lib.literalExpression
|
|
|
|
"pkgs.yt-dlp.override { phantomjsSupport = true; }";
|
|
|
|
};
|
|
|
|
|
|
|
|
archivePath = lib.mkOption {
|
2024-08-21 10:12:50 +00:00
|
|
|
type = lib.types.path;
|
2022-04-03 02:18:22 +00:00
|
|
|
description = ''
|
|
|
|
The location of the archive to be downloaded. Must be an absolute path.
|
|
|
|
'';
|
2024-08-21 10:12:50 +00:00
|
|
|
default = "/var/yt-dlp";
|
2022-07-30 08:22:24 +00:00
|
|
|
example = "/var/archives/yt-dlp-service";
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description =
|
2024-08-21 10:12:50 +00:00
|
|
|
"Global list of arguments to be passed to each yt-dlp job.";
|
2022-04-03 02:18:22 +00:00
|
|
|
default = [ "--download-archive videos" ];
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
2022-09-11 11:48:33 +00:00
|
|
|
"--verbose"
|
2022-07-30 08:22:24 +00:00
|
|
|
"--download-archive" "''${cfg.archivePath}/download-list"
|
|
|
|
"--concurrent-fragments" "2"
|
|
|
|
"--retries" "20"
|
2022-04-03 02:18:22 +00:00
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
jobs = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule jobType);
|
|
|
|
description = ''
|
|
|
|
A map of jobs for the archiving service.
|
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
arts = {
|
|
|
|
urls = [
|
|
|
|
"https://www.youtube.com/c/Jazza"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
2022-07-30 08:22:24 +00:00
|
|
|
extraArgs = [ "--date" "today" ];
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
compsci = {
|
|
|
|
urls = [
|
|
|
|
"https://www.youtube.com/c/K%C3%A1rolyZsolnai"
|
|
|
|
"https://www.youtube.com/c/TheCodingTrain"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-05 14:17:43 +00:00
|
|
|
# There's no need to go to the working directory since yt-dlp has the
|
|
|
|
# `--paths` flag.
|
2022-04-03 02:18:22 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2022-11-19 03:05:31 +00:00
|
|
|
systemd.services = lib.mapAttrs'
|
2024-08-21 10:12:50 +00:00
|
|
|
(name: job:
|
2022-11-19 03:05:31 +00:00
|
|
|
let
|
2024-08-21 10:12:50 +00:00
|
|
|
jobLevelArgs = lib.escapeShellArgs job.extraArgs;
|
2022-11-19 03:05:31 +00:00
|
|
|
in
|
|
|
|
lib.nameValuePair (jobUnitName name) {
|
2024-08-21 10:12:50 +00:00
|
|
|
inherit (job) startAt;
|
2022-11-19 03:05:31 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-08-21 10:11:31 +00:00
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
2022-11-19 03:05:31 +00:00
|
|
|
description = "yt-dlp archive job for group '${name}'";
|
|
|
|
documentation = [ "man:yt-dlp(1)" ];
|
|
|
|
enable = true;
|
|
|
|
path = [ cfg.package pkgs.coreutils ];
|
|
|
|
preStart = ''
|
2024-08-21 10:12:50 +00:00
|
|
|
mkdir -p ${lib.escapeShellArg job.archivePath}
|
2022-11-19 03:05:31 +00:00
|
|
|
'';
|
|
|
|
script = ''
|
|
|
|
yt-dlp ${serviceLevelArgs} ${jobLevelArgs} \
|
2024-08-21 10:12:50 +00:00
|
|
|
${lib.escapeShellArgs job.urls} \
|
|
|
|
--paths ${lib.escapeShellArg job.archivePath}
|
2022-11-19 03:05:31 +00:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
StandardOutput = "journal";
|
|
|
|
StandardError = "journal";
|
|
|
|
SystemCallFilter = "@system-service";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
cfg.jobs;
|
2022-07-21 01:54:00 +00:00
|
|
|
|
2022-11-19 03:05:31 +00:00
|
|
|
systemd.timers = lib.mapAttrs'
|
|
|
|
(name: value:
|
|
|
|
lib.nameValuePair (jobUnitName name) {
|
|
|
|
timerConfig = {
|
2023-10-27 05:25:08 +00:00
|
|
|
Persistent = true;
|
2022-11-19 03:05:31 +00:00
|
|
|
RandomizedDelaySec = "2min";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
cfg.jobs;
|
2022-04-03 02:18:22 +00:00
|
|
|
};
|
|
|
|
}
|