homepage: jellyfin init
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
{ lib, config, pkgs, serviceBase, ... }:
|
||||
let
|
||||
inherit (config.my) localhost;
|
||||
port = 8096;
|
||||
{ lib, config, pkgs, setup, ... }:
|
||||
let cfg = config.my.servers.jellyfin;
|
||||
in {
|
||||
options.my.servers.jellyfin = {
|
||||
enable = lib.mkEnableOption "enable";
|
||||
enableCron = lib.mkEnableOption "enable";
|
||||
};
|
||||
options.my.servers.jellyfin = setup.mkOptions "jellyfin" "flix" 8096;
|
||||
config = lib.mkIf config.my.servers.jellyfin.enable {
|
||||
environment.systemPackages = [ pkgs.jellyfin-ffmpeg ];
|
||||
services = {
|
||||
jellyfin = serviceBase // { };
|
||||
jellyfin = {
|
||||
enable = true;
|
||||
group = "piracy";
|
||||
};
|
||||
nginx = {
|
||||
enable = true;
|
||||
appendHttpConfig = ''
|
||||
@@ -20,7 +18,7 @@ in {
|
||||
map $request_uri $h264Level { ~(h264-level=)(.+?)& $2; }
|
||||
map $request_uri $h264Profile { ~(h264-profile=)(.+?)& $2; }
|
||||
'';
|
||||
virtualHosts."flix.${config.my.domain}" = {
|
||||
virtualHosts."${cfg.host}" = {
|
||||
forceSSL = true;
|
||||
enableACME = true;
|
||||
http2 = true;
|
||||
@@ -28,7 +26,7 @@ in {
|
||||
# use a variable to store the upstream proxy
|
||||
# in this example we are using a hostname which is resolved via DNS
|
||||
# (if you aren't using DNS remove the resolver line and change the variable to point to an IP address
|
||||
resolver ${localhost} valid=30;
|
||||
resolver ${config.my.localhost} valid=30;
|
||||
|
||||
location = / {
|
||||
return 302 http://$host/web/;
|
||||
@@ -37,7 +35,7 @@ in {
|
||||
|
||||
location = /web/ {
|
||||
# Proxy main Jellyfin traffic
|
||||
proxy_pass http://${localhost}:${toString port}/web/index.html;
|
||||
proxy_pass ${cfg.local}/web/index.html;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
@@ -48,11 +46,11 @@ in {
|
||||
'';
|
||||
locations = {
|
||||
"/" = {
|
||||
proxyPass = "http://${localhost}:${toString port}";
|
||||
proxyPass = cfg.local;
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
"/socket" = {
|
||||
proxyPass = "http://${localhost}:${toString port}";
|
||||
proxyPass = cfg.local;
|
||||
extraConfig = ''
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
@@ -60,7 +58,7 @@ in {
|
||||
'';
|
||||
};
|
||||
"~ /Items/(.*)/Images" = {
|
||||
proxyPass = "http://${localhost}:${toString port}";
|
||||
proxyPass = cfg.local;
|
||||
extraConfig = ''
|
||||
proxy_cache jellyfin;
|
||||
proxy_cache_revalidate on;
|
||||
@@ -68,7 +66,7 @@ in {
|
||||
'';
|
||||
};
|
||||
"~* ^/Videos/(.*)/(?!live)" = {
|
||||
proxyPass = "http://${localhost}:${toString port}";
|
||||
proxyPass = cfg.local;
|
||||
extraConfig = ''
|
||||
# Set size of a slice (this amount will be always requested from the backend by nginx)
|
||||
# Higher value means more latency, lower more overhead
|
||||
@@ -101,31 +99,27 @@ in {
|
||||
};
|
||||
};
|
||||
systemd = lib.mkIf config.my.servers.jellyfin.enableCron {
|
||||
services = {
|
||||
sub-sync = let
|
||||
sub-sync = pkgs.writeScriptBin "nextcloud-cronjob"
|
||||
(builtins.readFile ../../scripts/sub-sync.sh);
|
||||
in {
|
||||
restartIfChanged = true;
|
||||
description = "syncronizes subtitles downloaded & modified today";
|
||||
wantedBy = [ "default.target" ];
|
||||
path = [ pkgs.nix sub-sync ];
|
||||
serviceConfig = {
|
||||
Restart = "on-failure";
|
||||
RestartSec = 30;
|
||||
ExecStart = "${sub-sync}/bin/sub-sync all";
|
||||
Type = "forking";
|
||||
User = "root";
|
||||
};
|
||||
services.sub-sync = let
|
||||
sub-sync = pkgs.writeScriptBin "nextcloud-cronjob"
|
||||
(builtins.readFile ../../scripts/sub-sync.sh);
|
||||
in {
|
||||
restartIfChanged = true;
|
||||
description = "syncronizes subtitles downloaded & modified today";
|
||||
wantedBy = [ "default.target" ];
|
||||
path = [ pkgs.nix sub-sync ];
|
||||
serviceConfig = {
|
||||
Restart = "on-failure";
|
||||
RestartSec = 30;
|
||||
ExecStart = "${sub-sync}/bin/sub-sync all";
|
||||
Type = "forking";
|
||||
User = "root";
|
||||
};
|
||||
};
|
||||
timers = {
|
||||
sub-sync = {
|
||||
enable = true;
|
||||
description = "syncronizes subtitles downloaded & modified today";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = { OnCalendar = "20:00"; };
|
||||
};
|
||||
timers.sub-sync = {
|
||||
enable = true;
|
||||
description = "syncronizes subtitles downloaded & modified today";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = { OnCalendar = "20:00"; };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user