2023-10-31 19:40:51 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2024-03-10 17:26:18 +00:00
|
|
|
inherit (config.services.secrets) secrets;
|
2023-10-31 19:40:51 +00:00
|
|
|
rcloneMedia = pkgs.writeShellScriptBin "rclone-media" ''
|
|
|
|
${pkgs.rclone}/bin/rclone --config ${secrets.rclone_config.path} "$@"
|
|
|
|
'';
|
|
|
|
mountMedia = pkgs.writeShellScriptBin "mount-media" ''
|
2023-11-16 10:52:25 +00:00
|
|
|
umount -flR /Media || true
|
2023-11-13 17:49:31 +00:00
|
|
|
${rcloneMedia}/bin/rclone-media mount Media-Combine: /Media \
|
2023-10-31 19:40:51 +00:00
|
|
|
--allow-other \
|
|
|
|
--uid=${toString config.users.users.jellyfin.uid} \
|
|
|
|
--gid=${toString config.users.groups.jellyfin.gid} \
|
|
|
|
--fast-list \
|
|
|
|
--umask=666 \
|
2023-11-16 10:52:25 +00:00
|
|
|
--cache-dir=/caches/media \
|
2023-11-13 17:49:31 +00:00
|
|
|
--dir-cache-time=1m \
|
|
|
|
--vfs-cache-mode=full \
|
|
|
|
--vfs-cache-max-size=5g \
|
2023-11-16 10:52:25 +00:00
|
|
|
--vfs-cache-max-age=120m \
|
2023-10-31 19:40:51 +00:00
|
|
|
--log-level=INFO "$@"
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
rclone
|
|
|
|
rcloneMedia
|
|
|
|
fuse
|
|
|
|
fuse3
|
|
|
|
mountMedia
|
|
|
|
];
|
|
|
|
|
|
|
|
programs.fuse.userAllowOther = true;
|
|
|
|
|
|
|
|
systemd.services.jellyfin = {
|
|
|
|
wants = ["media-mount.service"];
|
|
|
|
after = ["media-mount.service"];
|
|
|
|
serviceConfig.ReadWritePaths = "/Media";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.media-mount = {
|
|
|
|
wantedBy = ["jellyfin.service"];
|
|
|
|
partOf = ["jellyfin.service"];
|
|
|
|
path = with pkgs; [
|
|
|
|
fuse
|
|
|
|
fuse3
|
|
|
|
];
|
|
|
|
serviceConfig.ExecStart = "${mountMedia}/bin/mount-media --syslog";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2023-11-16 10:52:25 +00:00
|
|
|
"d /caches - root root"
|
|
|
|
"d /caches/media - jellyfin jellyfin"
|
|
|
|
|
2023-10-31 19:40:51 +00:00
|
|
|
"d /Media - jellyfin jellyfin"
|
|
|
|
|
|
|
|
"d /root/.config - root root"
|
|
|
|
"d /root/.config/rclone - root root"
|
|
|
|
"L /root/.config/rclone/rclone.conf - - - - ${secrets.rclone_config.path}"
|
|
|
|
];
|
|
|
|
}
|