services: refactor

This commit is contained in:
Gabriel Arazas 2022-09-11 19:48:33 +08:00
parent 66092ff8c5
commit d20b192c41
6 changed files with 23 additions and 12 deletions

View File

@ -2,6 +2,7 @@
let
cfg = config.services.archivebox;
jobUnitName = name: "archivebox-job-${name}";
jobType = { name, options, ... }: {
options = {
links = lib.mkOption {
@ -104,7 +105,7 @@ in {
systemd.user.services = lib.mkMerge [
(lib.mapAttrs' (name: value:
lib.nameValuePair "archivebox-add-${name}" {
lib.nameValuePair (jobUnitName name) {
Unit = {
Description =
"Archivebox archive group '${name}' for ${cfg.archivePath}";
@ -152,7 +153,7 @@ in {
];
systemd.user.timers = lib.mapAttrs' (name: value:
lib.nameValuePair "archivebox-add-${name}" {
lib.nameValuePair (jobUnitName name) {
Unit = {
Description = "Archivebox additions for ${cfg.archivePath}";
After = "network.target";

View File

@ -3,6 +3,8 @@
let
cfg = config.services.gallery-dl;
jobUnitName = name: "gallery-dl-service-job-${name}";
settingsFormat = pkgs.formats.json { };
settingsFormatFile =
settingsFormat.generate "gallery-dl-service-config-${config.home.username}"
@ -162,7 +164,7 @@ in {
home.packages = [ cfg.package ];
systemd.user.services = lib.mapAttrs' (name: value:
lib.nameValuePair "gallery-dl-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
Unit = {
Description = "gallery-dl archive job for group '${name}'";
After = [ "default.target" ];
@ -189,7 +191,7 @@ in {
}) cfg.jobs;
systemd.user.timers = lib.mapAttrs' (name: value:
lib.nameValuePair "gallery-dl-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
Unit = {
Description = "gallery-dl archive job for group '${name}'";
Documentation = "man:gallery-dl(1)";

View File

@ -3,6 +3,8 @@
let
cfg = config.services.yt-dlp;
jobUnitName = name: "yt-dlp-archive-service-${name}";
serviceLevelArgs = lib.escapeShellArgs cfg.extraArgs;
jobType = { name, config, options, ... }: {
@ -134,7 +136,7 @@ in {
config = lib.mkIf cfg.enable {
systemd.user.services = lib.mapAttrs' (name: value:
lib.nameValuePair "yt-dlp-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
Unit = {
Description = "yt-dlp archive job for group '${name}'";
After = [ "default.target" ];
@ -163,7 +165,7 @@ in {
}) cfg.jobs;
systemd.user.timers = lib.mapAttrs' (name: value:
lib.nameValuePair "yt-dlp-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
Unit = {
Description = "yt-dlp archive job for group '${name}'";
Documentation = "man:yt-dlp(1)";

View File

@ -2,6 +2,7 @@
let
cfg = config.services.archivebox;
jobUnitName = name: "archivebox-job-${name}";
jobType = { name, options, ... }: {
options = {
urls = lib.mkOption {
@ -101,7 +102,7 @@ in {
in lib.mkIf cfg.enable {
systemd.services = lib.mkMerge [
(lib.mapAttrs' (name: value:
lib.nameValuePair "archivebox-add-${name}" {
lib.nameValuePair (jobUnitName name) {
description =
"Archivebox archive group '${name}' for ${cfg.archivePath}";
after = [ "network.target" ];
@ -165,7 +166,7 @@ in {
];
systemd.timers = lib.mapAttrs' (name: value:
lib.nameValuePair "archivebox-add-${name}" {
lib.nameValuePair (jobUnitName name) {
description =
"Archivebox archive group '${name}' for ${cfg.archivePath}";
after = [ "network.target" ];

View File

@ -3,6 +3,8 @@
let
cfg = config.services.gallery-dl;
jobUnitName = name: "gallery-dl-archive-job-${name}";
settingsFormat = pkgs.formats.json { };
settingsFormatFile =
settingsFormat.generate "gallery-dl-service-config" cfg.settings;
@ -156,7 +158,7 @@ in {
config = lib.mkIf cfg.enable {
systemd.services = lib.mapAttrs' (name: value:
lib.nameValuePair "gallery-dl-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
wantedBy = [ "multi-user.target" ];
description = "gallery-dl archive job for group '${name}'";
documentation = [ "man:gallery-dl(1)" ];
@ -208,7 +210,7 @@ in {
}) cfg.jobs;
systemd.timers = lib.mapAttrs' (name: value:
lib.nameValuePair "gallery-dl-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
timerConfig = {
Persistent = value.persistent;
RandomizedDelaySec = "2min";

View File

@ -5,6 +5,8 @@ let
serviceLevelArgs = lib.escapeShellArgs cfg.extraArgs;
jobUnitName = name: "yt-dlp-archive-service-${name}";
jobType = { name, config, options, ... }: {
options = {
urls = lib.mkOption {
@ -89,6 +91,7 @@ in {
default = [ "--download-archive videos" ];
example = lib.literalExpression ''
[
"--verbose"
"--download-archive" "''${cfg.archivePath}/download-list"
"--concurrent-fragments" "2"
"--retries" "20"
@ -130,7 +133,7 @@ in {
systemd.services = lib.mapAttrs' (name: value: let
jobLevelArgs = lib.escapeShellArgs value.extraArgs;
in
lib.nameValuePair "yt-dlp-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
wantedBy = [ "multi-user.target" ];
description = "yt-dlp archive job for group '${name}'";
documentation = [ "man:yt-dlp(1)" ];
@ -163,7 +166,7 @@ in {
}) cfg.jobs;
systemd.timers = lib.mapAttrs' (name: value:
lib.nameValuePair "yt-dlp-archive-service-${name}" {
lib.nameValuePair (jobUnitName name) {
timerConfig = {
Persistent = value.persistent;
RandomizedDelaySec = "2min";