From d20b192c4103f4c15170b343bd0b3b9259257477 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sun, 11 Sep 2022 19:48:33 +0800 Subject: [PATCH] services: refactor --- modules/home-manager/services/archivebox.nix | 5 +++-- modules/home-manager/services/gallery-dl.nix | 6 ++++-- modules/home-manager/services/yt-dlp.nix | 6 ++++-- modules/nixos/services/archivebox.nix | 5 +++-- modules/nixos/services/gallery-dl.nix | 6 ++++-- modules/nixos/services/yt-dlp.nix | 7 +++++-- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/modules/home-manager/services/archivebox.nix b/modules/home-manager/services/archivebox.nix index 69d0afd1..dfd384ef 100644 --- a/modules/home-manager/services/archivebox.nix +++ b/modules/home-manager/services/archivebox.nix @@ -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"; diff --git a/modules/home-manager/services/gallery-dl.nix b/modules/home-manager/services/gallery-dl.nix index 32bc16b2..60db23ed 100644 --- a/modules/home-manager/services/gallery-dl.nix +++ b/modules/home-manager/services/gallery-dl.nix @@ -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)"; diff --git a/modules/home-manager/services/yt-dlp.nix b/modules/home-manager/services/yt-dlp.nix index 1599cf18..c033af34 100644 --- a/modules/home-manager/services/yt-dlp.nix +++ b/modules/home-manager/services/yt-dlp.nix @@ -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)"; diff --git a/modules/nixos/services/archivebox.nix b/modules/nixos/services/archivebox.nix index 3471f95a..98fa95b8 100644 --- a/modules/nixos/services/archivebox.nix +++ b/modules/nixos/services/archivebox.nix @@ -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" ]; diff --git a/modules/nixos/services/gallery-dl.nix b/modules/nixos/services/gallery-dl.nix index 23dd5ae5..347f00c8 100644 --- a/modules/nixos/services/gallery-dl.nix +++ b/modules/nixos/services/gallery-dl.nix @@ -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"; diff --git a/modules/nixos/services/yt-dlp.nix b/modules/nixos/services/yt-dlp.nix index 08f1c76d..a01740d3 100644 --- a/modules/nixos/services/yt-dlp.nix +++ b/modules/nixos/services/yt-dlp.nix @@ -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";