diff --git a/devices/nos/default.nix b/devices/nos/default.nix index 4ca900df..57d39b5f 100644 --- a/devices/nos/default.nix +++ b/devices/nos/default.nix @@ -13,6 +13,7 @@ in { ./modules/mergerfs.nix ./modules/qbittorrent ./modules/snapraid.nix + ./modules/subtitles/sub-clean.nix ]; vars = { diff --git a/devices/nos/modules/subtitles/sub-clean.nix b/devices/nos/modules/subtitles/sub-clean.nix new file mode 100644 index 00000000..31862cfc --- /dev/null +++ b/devices/nos/modules/subtitles/sub-clean.nix @@ -0,0 +1,52 @@ +{ + config, + pkgs, + ... +}: let + inherit (config.vars) mainUser; + + scriptSrc = pkgs.fetchFromGitHub { + owner = "brianspilner01"; + repo = "media-server-scripts"; + rev = "00d9efcd37bb2667d23d7747240b59291cde64d3"; + hash = "sha256-Qql6Z+smU8vEJaai0POjdMnYpET9ak4NddNQevEQ8Ds="; + }; + + script = pkgs.concatTextFile { + name = "sub-clean.sh"; + files = ["${scriptSrc}/sub-clean.sh"]; + executable = true; + }; +in { + systemd = { + services.sub-clean = { + serviceConfig = { + Type = "oneshot"; + User = mainUser; + Group = config.users.users.${mainUser}.group; + }; + + path = with pkgs; [ + findutils + (writeShellApplication { + name = "sub-clean"; + runtimeInputs = [findutils gnugrep gawk]; + text = '' + exec ${script} "$@" + ''; + }) + ]; + + script = '' + find /data/anime -name '*.srt' -exec sub-clean "{}" \; + find /data/movies -name '*.srt' -exec sub-clean "{}" \; + find /data/tv -name '*.srt' -exec sub-clean "{}" \; + ''; + }; + timers.sub-clean = { + wantedBy = ["timers.target"]; + partOf = ["sub-clean.service"]; + timerConfig.OnCalendar = ["0:00:00"]; + }; + }; +}