From 1b5f020fef60654499dd4884b566864813758f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=BF=20corey=20=28they/them=29?= Date: Thu, 12 Mar 2026 13:44:50 -0700 Subject: [PATCH 1/2] feat: copy .mkv files to Unsorted on torrent completion Extend torrent-done.sh to automatically copy .mkv files (single files or folders containing .mkv files) to /mnt/media/Unsorted for Jellyfin. Add transmission user to media group for write access and include Unsorted in the hourly permissions timer. Co-Authored-By: Claude Opus 4.6 --- hosts/glyph/services/default.nix | 1 + hosts/glyph/services/samba.nix | 2 +- hosts/glyph/services/torrents.nix | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hosts/glyph/services/default.nix b/hosts/glyph/services/default.nix index 860b1cb4..a77a6da9 100644 --- a/hosts/glyph/services/default.nix +++ b/hosts/glyph/services/default.nix @@ -18,6 +18,7 @@ ]; users.groups.media = {}; users.users.mu.extraGroups = ["media"]; + users.users.${config.services.transmission.user}.extraGroups = ["media"]; services.cockpit.enable = true; services.openssh.enable = true; diff --git a/hosts/glyph/services/samba.nix b/hosts/glyph/services/samba.nix index 7ff474bf..7f184b65 100644 --- a/hosts/glyph/services/samba.nix +++ b/hosts/glyph/services/samba.nix @@ -64,7 +64,7 @@ "${pkgs.coreutils}/bin/chown -R ${defaultUsrGrp} archive" "${pkgs.coreutils}/bin/chown -R ${defaultUsrGrp} backup" # N.B.: /mnt/media/Music is used by Roon, not Jellyfin - "${pkgs.coreutils}/bin/chown -R ${jellyfinUsrGrp} media/Movies media/TV media/Video" + "${pkgs.coreutils}/bin/chown -R ${jellyfinUsrGrp} media/Movies media/TV media/Unsorted media/Video" "${pkgs.coreutils}/bin/chown -R ${defaultUsrGrp} media/Music" "${pkgs.coreutils}/bin/chown -R ${transmissionUsrGrp} torrents" "${pkgs.coreutils}/bin/chown -R ${defaultUsrGrp} unsorted" diff --git a/hosts/glyph/services/torrents.nix b/hosts/glyph/services/torrents.nix index 3fde9d81..78f963ba 100644 --- a/hosts/glyph/services/torrents.nix +++ b/hosts/glyph/services/torrents.nix @@ -49,6 +49,24 @@ --form-string "url=https://torrents.zx.dev" \ --form-string "url_title=View torrents" \ https://api.pushover.net/1/messages.json + + # Copy .mkv files to Unsorted for Jellyfin + UNSORTED="/mnt/media/Unsorted" + TORRENT_PATH="$TR_TORRENT_DIR/$TR_TORRENT_NAME" + + if [ -d "$TORRENT_PATH" ]; then + # Folder torrent: copy the folder if it contains at least one .mkv + if find "$TORRENT_PATH" -name '*.mkv' -print -quit | grep -q .; then + cp -r "$TORRENT_PATH" "$UNSORTED/" + chgrp -R media "$UNSORTED/$TR_TORRENT_NAME" + chmod -R g+rw "$UNSORTED/$TR_TORRENT_NAME" + fi + elif [[ "$TR_TORRENT_NAME" == *.mkv ]]; then + # Single .mkv file + cp "$TORRENT_PATH" "$UNSORTED/" + chgrp media "$UNSORTED/$TR_TORRENT_NAME" + chmod g+rw "$UNSORTED/$TR_TORRENT_NAME" + fi ''; cache-size-mb = 256; download-queue-enabled = true; @@ -62,7 +80,7 @@ webHome = pkgs.transmissionic; }; - systemd.services.transmission.path = [pkgs.curl]; + systemd.services.transmission.path = [pkgs.curl pkgs.findutils]; networking.firewall.allowedTCPPorts = [config.services.transmission.settings.peer-port]; } From 86df86291fbe47dce7bdcd923944be83cc888c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=BF=20corey=20=28they/them=29?= Date: Thu, 12 Mar 2026 13:45:35 -0700 Subject: [PATCH 2/2] fix: ensure /mnt/media/Unsorted is group-writable with setgid Add tmpfiles rule to set 2775 permissions on Unsorted so Samba's forced jellyfin user can write to it and new files inherit the media group. Co-Authored-By: Claude Opus 4.6 --- hosts/glyph/services/samba.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hosts/glyph/services/samba.nix b/hosts/glyph/services/samba.nix index 7f184b65..aaf2cb5c 100644 --- a/hosts/glyph/services/samba.nix +++ b/hosts/glyph/services/samba.nix @@ -52,6 +52,12 @@ // shares; }; + # Ensure Unsorted is group-writable with setgid so Samba (force user jellyfin) + # can write and new files inherit the media group + systemd.tmpfiles.rules = [ + "d /mnt/media/Unsorted 2775 ${config.services.jellyfin.user} ${config.services.jellyfin.group} -" + ]; + systemd.services.ensureSambaPermissions = { description = "Ensures correct permissions within Samba shares"; serviceConfig = {