1
0
Fork 0
nix-configuration/modules/services/jellyfin.nix

103 lines
3.1 KiB
Nix
Raw Normal View History

2024-07-12 18:11:26 +00:00
{
pkgs,
config,
lib,
...
}:
let
cfg = config.aux.system.services.jellyfin;
jellyfin-audio-save = pkgs.jellyfin.overrideAttrs (
finalAttrs: prevAttrs: { patches = [ ./jellyfin/jellyfin-audio-save-position.patch ]; }
);
2024-07-12 18:11:26 +00:00
in
{
options = {
aux.system.services.jellyfin = {
2024-09-08 15:58:56 +00:00
enable = lib.mkEnableOption "Enables the Jellyfin media streaming service.";
2024-07-12 18:11:26 +00:00
home = lib.mkOption {
2024-09-07 17:44:14 +00:00
default = "/var/lib/jellyfin";
2024-07-12 18:11:26 +00:00
type = lib.types.str;
description = "Where to store Jellyfin's files";
};
url = lib.mkOption {
default = "";
type = lib.types.str;
description = "The complete URL where Jellyfin is hosted.";
example = "https://jellyfin.example.com";
};
};
};
config = lib.mkIf cfg.enable {
aux.system.users.media.enable = true;
services = {
nginx.virtualHosts."${cfg.url}" = {
2024-09-09 03:47:53 +00:00
useACMEHost = pkgs.util.getDomainFromURL cfg.url;
2024-07-12 18:11:26 +00:00
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:8096";
2024-07-12 18:11:26 +00:00
proxyWebsockets = true;
extraConfig = ''
# Taken from https://jellyfin.org/docs/general/networking/nginx/
client_max_body_size 20M;
# Security / XSS Mitigation Headers
# NOTE: X-Frame-Options may cause issues with the webOS app
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Host $host;
# Disable buffering when the nginx proxy gets very resource heavy upon streaming
proxy_buffering off;
'';
};
locations."/socket" = {
proxyPass = "http://127.0.0.1:8096";
2024-07-12 18:11:26 +00:00
proxyWebsockets = true;
extraConfig = ''
# Proxy Jellyfin Websockets traffic
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Host $host;
'';
};
};
jellyfin = {
enable = true;
dataDir = cfg.home;
group = "media";
package = jellyfin-audio-save;
};
2024-07-12 18:11:26 +00:00
};
systemd.services = {
jellyfin = {
# Install packages for plugins
path = with pkgs; [
id3v2
yt-dlp
];
unitConfig.RequiresMountsFor = cfg.home;
};
nginx.wants = [ config.systemd.services.jellyfin.name ];
};
# Set permissions for media folders
systemd.tmpfiles.rules = [ "Z /storage/Media 6775 aires media - -" ];
2024-07-12 18:11:26 +00:00
};
}