mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
services/gallery-dl: add job-specific settings
The arguments are also arranged to let the resulting settings cascade from service-wide to job-specific settings.
This commit is contained in:
parent
01bf630a9d
commit
dd9921fc7e
@ -53,6 +53,19 @@ let
|
||||
]
|
||||
'';
|
||||
};
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = settingsFormat.type;
|
||||
description = ''
|
||||
Job-specific settings to be overridden to the service-wide settings.
|
||||
'';
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
extractor.directory = [ "{category}" "{user|artist|uploader}" ];
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
@ -146,13 +159,19 @@ in {
|
||||
|
||||
Service.ExecStart = let
|
||||
scriptName = "gallery-dl-service-${config.home.username}-${name}";
|
||||
jobSpecificSettingsFile =
|
||||
settingsFormat.generate "gallery-dl-service-job-${name}-settings"
|
||||
value.settings;
|
||||
archiveScript = pkgs.writeShellScriptBin scriptName ''
|
||||
${cfg.package}/bin/gallery-dl ${
|
||||
lib.concatStringsSep " " cfg.extraArgs
|
||||
} ${lib.concatStringsSep " " value.extraArgs} ${
|
||||
lib.escapeShellArgs cfg.extraArgs
|
||||
} ${
|
||||
lib.optionalString (cfg.settings != null)
|
||||
"--config ${settingsFormatFile}"
|
||||
} --directory ${cfg.archivePath} ${lib.escapeShellArgs value.urls}
|
||||
} ${lib.escapeShellArgs value.extraArgs} ${
|
||||
lib.optionalString (value.settings != null)
|
||||
"--config ${jobSpecificSettingsFile}"
|
||||
} --destination ${cfg.archivePath} ${lib.escapeShellArgs value.urls}
|
||||
'';
|
||||
in "${archiveScript}/bin/${scriptName}";
|
||||
}) cfg.jobs;
|
||||
|
@ -52,6 +52,19 @@ let
|
||||
]
|
||||
'';
|
||||
};
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = settingsFormat.type;
|
||||
description = ''
|
||||
Job-specific settings to be overridden to the service-wide settings.
|
||||
'';
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
extractor.directory = [ "{category}" "{user|artist|uploader}" ];
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
@ -137,17 +150,32 @@ in {
|
||||
description = "gallery-dl archive job for group '${name}'";
|
||||
documentation = [ "man:gallery-dl(1)" ];
|
||||
enable = true;
|
||||
path = [ cfg.package ] ++ (with pkgs; [ coreutils ffmpeg ]);
|
||||
path = [ cfg.package ] ++ (with pkgs; [ brotli coreutils ffmpeg ]);
|
||||
preStart = ''
|
||||
mkdir -p ${lib.escapeShellArg cfg.archivePath}
|
||||
'';
|
||||
script = ''
|
||||
gallery-dl ${lib.concatStringsSep " " cfg.extraArgs} ${
|
||||
lib.concatStringsSep " " value.extraArgs
|
||||
} ${
|
||||
|
||||
# Order matters here. We're letting service-level arguments and
|
||||
# settings to be overridden with job-specific things as much as
|
||||
# possible especially with the settings.
|
||||
#
|
||||
# Regarding to settings (`settings`) and extra arguments
|
||||
# (`extraArgs`), the settings is the last applied argument with
|
||||
# `--config` option. This means that it will cascade resultings
|
||||
# settings from `extraArgs` if there's any related option that is
|
||||
# given like another `--config` for example.
|
||||
script = let
|
||||
jobLevelSettingsFile =
|
||||
settingsFormat.generate "gallery-dl-job-${name}-settings"
|
||||
value.settings;
|
||||
in ''
|
||||
gallery-dl ${lib.escapeShellArgs cfg.extraArgs} ${
|
||||
lib.optionalString (cfg.settings != null)
|
||||
"--config ${settingsFormatFile}"
|
||||
} --directory ${lib.escapeShellArg cfg.archivePath} ${
|
||||
} ${lib.escapeShellArgs value.extraArgs} ${
|
||||
lib.optionalString (value.settings != null)
|
||||
"--config ${jobLevelSettingsFile}"
|
||||
} --destination ${lib.escapeShellArg cfg.archivePath} ${
|
||||
lib.escapeShellArgs value.urls
|
||||
}
|
||||
'';
|
||||
|
@ -160,7 +160,7 @@ in
|
||||
|
||||
extraArgs = [
|
||||
# Record all downloaded files in an archive file.
|
||||
"--download-archive ${config.services.gallery-dl.archivePath}/photos"
|
||||
"--download-archive" "${config.services.gallery-dl.archivePath}/photos"
|
||||
|
||||
# Write metadata to separate JSON files.
|
||||
"--write-metadata"
|
||||
|
Loading…
Reference in New Issue
Block a user