2022-04-03 02:10:29 +00:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gallery-dl;
|
|
|
|
|
|
|
|
settingsFormat = pkgs.formats.json { };
|
|
|
|
settingsFormatFile =
|
|
|
|
settingsFormat.generate "gallery-dl-service-config" cfg.settings;
|
|
|
|
|
|
|
|
jobType = { name, config, options, ... }: {
|
|
|
|
options = {
|
|
|
|
urls = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
A list of URLs to be downloaded to <command>gallery-dl</command>. Please
|
|
|
|
see the list of extractors with <option>--list-extractors</option>.
|
|
|
|
'';
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
"https://www.deviantart.com/xezeno"
|
|
|
|
"https://www.pixiv.net/en/users/60562229"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
startAt = lib.mkOption {
|
|
|
|
type = with lib.types; str;
|
|
|
|
description = ''
|
|
|
|
Indicates how frequent the download will occur. The given schedule
|
|
|
|
should follow the format as described from
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>systemd.time</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum>
|
|
|
|
</citerefentry>.
|
|
|
|
'';
|
|
|
|
default = "daily";
|
|
|
|
example = "*-*-3/4";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description = ''
|
|
|
|
Job-specific extra arguments to be passed to the
|
|
|
|
<command>gallery-dl</command>.
|
|
|
|
'';
|
|
|
|
default = [ ];
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
"--date 'today-1week'" # get only videos from a week ago
|
|
|
|
"--output '%(uploader)s/%(title)s.%(ext)s'" # download them in the respective directory
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.services.gallery-dl = {
|
|
|
|
enable = lib.mkEnableOption "archiving services with gallery-dl";
|
|
|
|
|
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
description =
|
|
|
|
"Package containing the <command>gallery-dl</command> binary.";
|
|
|
|
default = pkgs.gallery-dl;
|
|
|
|
defaultText = lib.literalExpression "pkgs.gallery-dl";
|
|
|
|
};
|
|
|
|
|
|
|
|
archivePath = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The location of the archive to be downloaded. Take note it is assumed
|
|
|
|
to be created at the time of running the service.
|
|
|
|
'';
|
|
|
|
default = "/archives/gallery-dl-service";
|
2022-04-29 08:55:09 +00:00
|
|
|
example = lib.literalExpression "/var/archives/gallery-dl-services";
|
2022-04-03 02:10:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
settings = lib.mkOption {
|
|
|
|
type = settingsFormat.type;
|
|
|
|
description = ''
|
|
|
|
The configuration to be used for the service. If the value is empty,
|
|
|
|
the service will not pass any option relating to the custom
|
|
|
|
configuration.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
cache.file = "~/.gallery-dl-cache.sqlite3";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
|
|
|
description =
|
|
|
|
"List of arguments to be passed to <command>gallery-dl</command>.";
|
|
|
|
default = [ ];
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
[
|
|
|
|
"--retries 20"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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.pixiv.net/en/users/60562229"
|
|
|
|
"https://www.deviantart.com/xezeno"
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
|
|
|
};
|
|
|
|
|
|
|
|
mango = {
|
|
|
|
urls = [
|
|
|
|
# TODO: Put some manga sites here
|
|
|
|
];
|
|
|
|
startAt = "weekly";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services = lib.mapAttrs' (name: value:
|
|
|
|
lib.nameValuePair "gallery-dl-archive-service-${name}" {
|
|
|
|
after = [ "network.target" ];
|
|
|
|
description = "gallery-dl archive job for group '${name}'";
|
|
|
|
documentation = [ "man:gallery-dl(1)" ];
|
|
|
|
enable = true;
|
|
|
|
path = [ cfg.package ] ++ (with pkgs; [ coreutils ffmpeg ]);
|
2022-04-22 05:13:17 +00:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${lib.escapeShellArg cfg.archivePath}
|
|
|
|
'';
|
2022-04-03 02:10:29 +00:00
|
|
|
script = ''
|
2022-04-22 05:13:17 +00:00
|
|
|
gallery-dl ${lib.concatStringsSep " " cfg.extraArgs} ${
|
2022-04-06 02:48:29 +00:00
|
|
|
lib.concatStringsSep " " value.extraArgs
|
|
|
|
} ${
|
2022-04-03 02:10:29 +00:00
|
|
|
lib.optionalString (cfg.settings != null)
|
|
|
|
"--config ${settingsFormatFile}"
|
2022-04-06 02:48:29 +00:00
|
|
|
} --directory ${lib.escapeShellArg cfg.archivePath} ${
|
|
|
|
lib.escapeShellArgs value.urls
|
|
|
|
}
|
2022-04-03 02:10:29 +00:00
|
|
|
'';
|
|
|
|
startAt = value.startAt;
|
2022-04-16 16:17:52 +00:00
|
|
|
serviceConfig = {
|
2022-04-29 08:55:09 +00:00
|
|
|
LockPersonality = true;
|
2022-04-16 16:17:52 +00:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateTmp = true;
|
2022-04-29 08:55:09 +00:00
|
|
|
PrivateUsers = true;
|
|
|
|
PrivateDevices = true;
|
2022-04-22 05:13:17 +00:00
|
|
|
ProtectControlGroups = true;
|
2022-04-16 16:17:52 +00:00
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelLogs = true;
|
2022-04-29 08:55:09 +00:00
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
SystemCallFilter = "@system-service";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
2022-04-16 16:17:52 +00:00
|
|
|
};
|
2022-07-05 14:17:43 +00:00
|
|
|
unitConfig = {
|
|
|
|
AssertPathIsReadWrite = cfg.archivePath;
|
|
|
|
AssertPathIsDirectory = cfg.archivePath;
|
|
|
|
};
|
2022-04-03 02:10:29 +00:00
|
|
|
}) cfg.jobs;
|
|
|
|
};
|
|
|
|
}
|