From 17c3d7a98f297687b1b500e01d3921497f3c4326 Mon Sep 17 00:00:00 2001 From: Danilo Reyes Date: Wed, 12 Jun 2024 23:59:44 -0600 Subject: [PATCH] download & stream-dl units + ryot disabled --- hosts/miniserver/configuration.nix | 50 +++------------ hosts/miniserver/docker.nix | 36 +++++------ hosts/miniserver/servers.nix | 9 ++- modules/scripts.nix | 5 +- modules/scripts/download.nix | 99 ++++++++++++++++++++++-------- modules/scripts/stream-dl.nix | 47 ++++++++++++++ 6 files changed, 161 insertions(+), 85 deletions(-) create mode 100644 modules/scripts/stream-dl.nix diff --git a/hosts/miniserver/configuration.nix b/hosts/miniserver/configuration.nix index 6d3f2b8..479d5fe 100644 --- a/hosts/miniserver/configuration.nix +++ b/hosts/miniserver/configuration.nix @@ -1,8 +1,4 @@ -{ config, lib, pkgs, ... }: -let - stream-dl = pkgs.writeScriptBin "stream-dl" - (builtins.readFile ../../scripts/stream-dl.sh); -in { +{ pkgs, ... }: { imports = [ ./servers.nix ./docker.nix ./hardware-configuration.nix ../../base.nix ]; my = { @@ -15,6 +11,10 @@ in { python.enable = true; sh.enable = true; }; + units = { + download.enable = true; + stream-dl.enable = true; + }; scripts = { run.enable = true; split-dir.enable = true; @@ -120,20 +120,8 @@ in { wantedBy = [ "multi-user.target" ]; }; }; - timers = { }; user = { services = { - "stream@" = { - description = "monitors a stream channel for online streams."; - restartIfChanged = true; - wantedBy = [ "default.target" ]; - path = [ pkgs.nix stream-dl ]; - serviceConfig = { - Restart = "on-failure"; - RestartSec = 30; - ExecStart = "${stream-dl}/bin/stream-dl %I"; - }; - }; # unpackerr = { # enable = true; # restartIfChanged = true; @@ -159,29 +147,11 @@ in { }; }; }; - timers = let - streamTimer = { - enable = true; - description = "monitors a stream channel for online streams."; - wantedBy = [ "timers.target" ]; - timerConfig = { - OnBootSec = "5min"; - OnUnitActiveSec = "65min"; - RandomizedDelaySec = 30; - }; - }; - in { - "stream@johnneal911" = streamTimer // { }; - "stream@uk2011boy" = streamTimer // { }; - "stream@tommy9x6" = streamTimer // { }; - "stream@brocollirob" = streamTimer // { }; - "stream@tomayto\\x20picarto" = streamTimer // { }; - qbit_manage = { - enable = true; - description = "Tidy up my torrents"; - wantedBy = [ "timers.target" ]; - timerConfig = { OnCalendar = "*:0/10"; }; - }; + timers.qbit_manage = { + enable = true; + description = "Tidy up my torrents"; + wantedBy = [ "timers.target" ]; + timerConfig = { OnCalendar = "*:0/10"; }; }; }; }; diff --git a/hosts/miniserver/docker.nix b/hosts/miniserver/docker.nix index af734e7..bd693a3 100644 --- a/hosts/miniserver/docker.nix +++ b/hosts/miniserver/docker.nix @@ -60,24 +60,24 @@ [ "/var/lib/docker-configs/vocechat:/home/vocechat-server/data" ]; environment = { TZ = "America/Mexico_City"; }; }; - ryot = { - image = "ghcr.io/ignisda/ryot:latest"; - ports = [ "8765:8000" ]; - environment = { - TZ = "America/Mexico_City"; - DATABASE_URL = "postgres:///ryot?host=${postgresSocket}"; - SERVER_INSECURE_COOKIE = "true"; - VIDEO_GAMES_TWITCH_CLIENT_ID = "tfu0hw0zbdbu4lco4h72nqkb8krxp9"; - VIDEO_GAMES_TWITCH_CLIENT_SECRET = "582ecfb01ihv6wnt8zbc9pf3hs9p54"; - }; - volumes = [ "${postgresSocket}:${postgresSocket}" ]; - labels = { - "flame.type" = "application"; - "flame.name" = "Ryot"; - "flame.url" = "tracker.servidos.lat"; - "flame.icon" = "radar"; - }; - }; + # ryot = { + # image = "ghcr.io/ignisda/ryot:v5.5.0"; + # ports = [ "8765:8000" ]; + # environment = { + # TZ = "America/Mexico_City"; + # DATABASE_URL = "postgres:///ryot?host=${postgresSocket}"; + # # FRONTEND_INSECURE_COOKIES = "true"; + # VIDEO_GAMES_TWITCH_CLIENT_ID = "tfu0hw0zbdbu4lco4h72nqkb8krxp9"; + # VIDEO_GAMES_TWITCH_CLIENT_SECRET = "582ecfb01ihv6wnt8zbc9pf3hs9p54"; + # }; + # volumes = [ "${postgresSocket}:${postgresSocket}" ]; + # labels = { + # "flame.type" = "application"; + # "flame.name" = "Ryot"; + # "flame.url" = "tracker.servidos.lat"; + # "flame.icon" = "radar"; + # }; + # }; multi-scrobbler = { image = "foxxmd/multi-scrobbler"; ports = [ "9078:9078" ]; diff --git a/hosts/miniserver/servers.nix b/hosts/miniserver/servers.nix index 0941507..0abc55c 100644 --- a/hosts/miniserver/servers.nix +++ b/hosts/miniserver/servers.nix @@ -90,6 +90,11 @@ in { jellyfin = base // { }; # prowlarr.enable = true; # jira.enable = true; + # adguardhome = { + # enable = true; + # mutableSettings = true; + # openFirewall = true; + # }; microbin = { enable = true; settings = { @@ -218,7 +223,7 @@ in { "OC\\Preview\\Movie" ]; }; - phpExtraExtensions = all: [ all.pdlib all.bz2 ]; + phpExtraExtensions = all: [ all.pdlib all.bz2 all.ldap ]; }; postgresql = let dbNames = @@ -240,7 +245,7 @@ in { }; systemd = { services = { - nextcloud-cron = { path = [ pkgs.perl ]; }; + nextcloud-cron.path = [ pkgs.perl ]; # sub-sync = { # restartIfChanged = true; # description = "syncronizes subtitles downloaded & modified today"; diff --git a/modules/scripts.nix b/modules/scripts.nix index efa30d5..4585c7a 100644 --- a/modules/scripts.nix +++ b/modules/scripts.nix @@ -1,4 +1,4 @@ -{ ... }: { +{ lib, ... }: { imports = [ ./scripts/download.nix ./scripts/ffmpeg4discord.nix @@ -10,5 +10,8 @@ ./scripts/split-dir.nix ./scripts/tasks.nix ./scripts/update-dns.nix + ./scripts/stream-dl.nix ]; + my.units.download.enable = lib.mkDefault false; + my.units.stream-dl.enable = lib.mkDefault false; } diff --git a/modules/scripts/download.nix b/modules/scripts/download.nix index f4ad5cb..57a8d7d 100644 --- a/modules/scripts/download.nix +++ b/modules/scripts/download.nix @@ -1,42 +1,93 @@ -{ pkgs, lib, ... }: { +{ pkgs, lib, config, ... }: { imports = [ ./base.nix ]; + options.my.units.download.enable = lib.mkEnableOption "enable"; config = { home-manager.users.jawz = { xdg.configFile."gallery-dl/config.json".source = ../../dotfiles/gallery-dl/config.json; services.lorri.enable = true; - programs = { - bash = { - shellAliases = { - comic = - ''download -u jawz -i "$(cat $LC | fzf --multi --exact -i)"''; - gallery = - ''download -u jawz -i "$(cat $LW | fzf --multi --exact -i)"''; - dl = "download -u jawz -i"; + programs.bash = { + shellAliases = { + comic = ''download -u jawz -i "$(cat $LC | fzf --multi --exact -i)"''; + gallery = + ''download -u jawz -i "$(cat $LW | fzf --multi --exact -i)"''; + dl = "download -u jawz -i"; + }; + initExtra = '' + list_root=$XDG_CONFIG_HOME/jawz/lists/jawz + export LW=$list_root/watch.txt + export LI=$list_root/instant.txt + export LC=$list_root/comic.txt + ''; + }; + }; + systemd.user = lib.mkIf config.my.units.download.enable { + services = let + mkDownloadService = desc: execStartCmd: { + restartIfChanged = true; + description = "Downloads ${desc}"; + wantedBy = [ "default.target" ]; + path = [ pkgs.bash ]; + serviceConfig = { + Restart = "on-failure"; + RestartSec = 30; + ExecStart = execStartCmd; }; - initExtra = '' - list_root=$XDG_CONFIG_HOME/jawz/lists/jawz - export LW=$list_root/watch.txt - export LI=$list_root/instant.txt - export LC=$list_root/comic.txt - ''; + }; + in { + tuhmayto = mkDownloadService "tuhmayto stuff" '' + /etc/profiles/per-user/jawz/bin/download \ + -u jawz -i https://twitter.com/tuhmayto/media \ + https://www.furaffinity.net/user/tuhmayto/''; + "download@" = mkDownloadService "post from multiple sources" + "/etc/profiles/per-user/jawz/bin/download %I"; + "instagram@" = mkDownloadService "post types from instagram" '' + /etc/profiles/per-user/jawz/bin/download \ + instagram -u jawz -t %I''; + }; + timers = let + downloadTimer = time: delay: { + enable = true; + description = "Downloads post types from different sites"; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = time; + RandomizedDelaySec = delay; + Persistent = true; + }; + }; + in { + "instagram@stories" = downloadTimer "*-*-* 08:12:00" 120 // { }; + "download@main" = downloadTimer "*-*-* 06,18:02:00" 30 // { }; + "download@push" = downloadTimer "*:0/5" 30 // { }; + "download@manga" = downloadTimer "Fri *-*-* 03:08:00" 30 // { }; + # "download@kemono" = downloadTimer + # "*-*-1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 18:06:00" 60 // { }; + tuhmayto = { + enable = true; + description = "Downloads tuhmayto stuff"; + wantedBy = [ "timers.target" ]; + timerConfig = { OnCalendar = "*:0/10"; }; }; }; }; - users.users.jawz.packages = [ pkgs.gallery-dl ]; my.scripts.download = { enable = lib.mkDefault false; install = true; service = false; name = "download"; - package = with pkgs.python3Packages; - (buildPythonApplication { - pname = "download"; - version = "2.5"; - src = ../../scripts/download/.; - buildInputs = [ setuptools ]; - propagatedBuildInputs = [ pyyaml types-pyyaml yt-dlp ]; - }); + package = pkgs.python3Packages.buildPythonApplication { + pname = "download"; + version = "2.5"; + src = ../../scripts/download/.; + buildInputs = + [ pkgs.python3Packages.setuptools pkgs.gallery-dl pkgs.ffmpeg ]; + propagatedBuildInputs = with pkgs.python3Packages; [ + pyyaml + types-pyyaml + yt-dlp + ]; + }; }; }; } diff --git a/modules/scripts/stream-dl.nix b/modules/scripts/stream-dl.nix new file mode 100644 index 0000000..eae2376 --- /dev/null +++ b/modules/scripts/stream-dl.nix @@ -0,0 +1,47 @@ +{ pkgs, lib, config, ... }: { + imports = [ ./base.nix ]; + options.my.units.stream-dl.enable = lib.mkEnableOption "enable"; + config = let + stream-dl = pkgs.writeScriptBin "stream-dl" + (builtins.readFile ../../scripts/stream-dl.sh); + in { + systemd.user = lib.mkIf config.my.units.stream-dl.enable { + services."stream@" = { + description = "monitors a stream channel for online streams."; + restartIfChanged = true; + wantedBy = [ "default.target" ]; + path = [ pkgs.nix stream-dl ]; + serviceConfig = { + Restart = "on-failure"; + RestartSec = 30; + ExecStart = "${stream-dl}/bin/stream-dl %I"; + }; + }; + timers = let + streamTimer = { + enable = true; + description = "monitors a stream channel for online streams."; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnBootSec = "5min"; + OnUnitActiveSec = "65min"; + RandomizedDelaySec = 30; + }; + }; + in { + "stream@johnneal911" = streamTimer // { }; + "stream@uk2011boy" = streamTimer // { }; + "stream@tommy9x6" = streamTimer // { }; + "stream@brocollirob" = streamTimer // { }; + "stream@tomayto\\x20picarto" = streamTimer // { }; + }; + }; + my.scripts.stream-dl = { + enable = lib.mkDefault false; + install = true; + service = false; + name = "stream-dl"; + package = stream-dl; + }; + }; +}