nix-configs

Personal NixOS and home-manager configuration files
Log | Files | Refs

commit 671150ef78bf6e6b5c1df575892c9d66cf9763e1
parent d676c4d339ce3db2047d179caf1a9627f671241e
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Mon, 18 Aug 2025 20:22:45 +0100

Move media-sort, improve sort script

Diffstat:
Mcommon/tank-sort.nix | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mmachines/ilias.nix | 2--
Mmachines/minerva.nix | 2--
3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/common/tank-sort.nix b/common/tank-sort.nix @@ -1,7 +1,11 @@ { pkgs, username, ... }: let + media-sort = pkgs.callPackage ./media-sort.nix {}; + tank-sort = pkgs.writeShellScriptBin "tank-sort" '' + set -euo pipefail # Exit on any error + # variables temp_mount="$(mktemp -d)" rclone_remote="seedbox:" @@ -9,16 +13,63 @@ let template_tvshows="{{ .Name }}/{{ .Name }} S{{ printf \"%02d\" .Season }}E{{ printf \"%02d\" .Episode }}{{ if ne .ExtraEpisode -1 }}-{{ printf \"%02d\" .ExtraEpisode }}{{end}}.{{ .Ext }}" destination_movies="/tank/media/videos/movies" template_movies="{{ .Name }} ({{ .Year }})/{{ .Name }}.{{ .Ext }}" + + # Cleanup function + cleanup() { + echo "Cleaning up..." + if mountpoint -q "$temp_mount" 2>/dev/null; then + fusermount -uz "$temp_mount" 2>/dev/null || true + fi + if [ -d "$temp_mount" ]; then + rmdir "$temp_mount" 2>/dev/null || true + fi + } + trap cleanup EXIT + # mount remote - ${pkgs.rclone}/bin/rclone mount "$rclone_remote" "$temp_mount" --daemon + echo "Mounting rclone remote..." + if ! ${pkgs.rclone}/bin/rclone mount "$rclone_remote" "$temp_mount" \ + --vfs-cache-mode writes \ + --allow-other \ + --daemon-timeout 10s \ + --daemon; then + echo "ERROR: Failed to mount rclone remote" + exit 1 + fi + + # Wait for mount to be ready + echo "Waiting for mount to be ready..." + for i in {1..30}; do + if mountpoint -q "$temp_mount" 2>/dev/null; then + echo "Mount is ready" + break + fi + if [ $i -eq 30 ]; then + echo "ERROR: Mount failed to become ready within 30 seconds" + exit 1 + fi + sleep 1 + done + # sorting process - media-sort --action copy --concurrency 1 --accuracy-threshold 90 --tv-dir "$destination_tvshows" --movie-dir "$destination_movies" --tv-template "$template_tvshows" --movie-template "$template_movies" --recursive --overwrite-if-larger --extensions "mp4,m4v,mkv" "$temp_mount" - # unmount remote and remove - fusermount -uz "$temp_mount" 2>/dev/null - find "$temp_mount" -maxdepth 1 -mount -type d -empty -delete -print + echo "Starting media sort..." + ${media-sort}/bin/media-sort \ + --action copy \ + --concurrency 1 \ + --accuracy-threshold 90 \ + --tv-dir "$destination_tvshows" \ + --movie-dir "$destination_movies" \ + --tv-template "$template_tvshows" \ + --movie-template "$template_movies" \ + --recursive \ + --overwrite-if-larger \ + --extensions "mp4,m4v,mkv" \ + "$temp_mount" + + echo "Media sort completed successfully" ''; in { - environment.systemPackages = [tank-sort]; + environment.systemPackages = [tank-sort media-sort]; systemd.timers.tank-sort = { wantedBy = [ "timers.target" ]; @@ -31,10 +82,15 @@ in { systemd.services.tank-sort = { script = "tank-sort"; - path = [ "/run/current-system/sw" ]; + path = with pkgs; [ "/run/current-system/sw" rclone fuse util-linux media-sort ]; serviceConfig = { Type = "oneshot"; User = "${username}"; + Restart = "no"; + RestartSec = "30s"; + SupplementaryGroups = [ "fuse" ]; + WorkingDirectory = "/tmp"; + TimeoutStartSec = "300s"; }; }; } diff --git a/machines/ilias.nix b/machines/ilias.nix @@ -13,7 +13,6 @@ privatekey, ... }: let - media-sort = import ../common/media-sort.nix {inherit pkgs;}; # home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz; # Stable home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/master.tar.gz; # Unstable in { @@ -94,7 +93,6 @@ in { gallery-dl imagemagick jdupes - media-sort mmv lf mnamer diff --git a/machines/minerva.nix b/machines/minerva.nix @@ -13,7 +13,6 @@ privatekey, ... }: let - media-sort = import ../common/media-sort.nix {inherit pkgs;}; # home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz; home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/master.tar.gz; in { @@ -72,7 +71,6 @@ in { # Packages environment.systemPackages = with pkgs; [ atool - media-sort brightnessctl dos2unix firefox