refactor(plex): access

This commit is contained in:
arcnmx 2024-01-21 11:34:19 -08:00
parent 2b9d14d832
commit 1a4b5ee8b2
3 changed files with 60 additions and 68 deletions

View file

@ -1,32 +1,64 @@
{ {
config, config,
lib, lib,
meta,
... ...
}: }: let
with lib; { inherit (lib.options) mkOption;
services.nginx.virtualHosts."plex.${config.networking.domain}" = { inherit (lib.modules) mkIf;
locations = { cfg = config.services.plex;
"/" = { access = config.services.nginx.access.plex;
proxyPass = meta.tailnet.yukari.pp 4 32400; in {
extraConfig = '' options.services.nginx.access.plex = with lib.types; {
proxy_set_header Upgrade $http_upgrade; url = mkOption {
proxy_set_header Connection "upgrade"; type = str;
proxy_redirect off; };
proxy_buffering off; domain = mkOption {
proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier; type = str;
proxy_set_header X-Plex-Device $http_x_plex_device; default = "plex.${config.networking.domain}";
proxy_set_header X-Plex-Device-Name $http_x_plex_device_name; };
proxy_set_header X-Plex-Platform $http_x_plex_platform; localDomain = mkOption {
proxy_set_header X-Plex-Platform-Version $http_x_plex_platform_version; type = str;
proxy_set_header X-Plex-Product $http_x_plex_product; default = "plex.local.${config.networking.domain}";
proxy_set_header X-Plex-Token $http_x_plex_token; };
proxy_set_header X-Plex-Version $http_x_plex_version; };
proxy_set_header X-Plex-Nocache $http_x_plex_nocache; config.services.nginx = {
proxy_set_header X-Plex-Provides $http_x_plex_provides; access.plex = mkIf cfg.enable {
proxy_set_header X-Plex-Device-Vendor $http_x_plex_device_vendor; url = "http://localhost:32400";
proxy_set_header X-Plex-Model $http_x_plex_model; };
''; virtualHosts = let
extraConfig = ''
# Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause
send_timeout 100m;
# Plex headers
proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier;
proxy_set_header X-Plex-Device $http_x_plex_device;
proxy_set_header X-Plex-Device-Name $http_x_plex_device_name;
proxy_set_header X-Plex-Platform $http_x_plex_platform;
proxy_set_header X-Plex-Platform-Version $http_x_plex_platform_version;
proxy_set_header X-Plex-Product $http_x_plex_product;
proxy_set_header X-Plex-Token $http_x_plex_token;
proxy_set_header X-Plex-Version $http_x_plex_version;
proxy_set_header X-Plex-Nocache $http_x_plex_nocache;
proxy_set_header X-Plex-Provides $http_x_plex_provides;
proxy_set_header X-Plex-Device-Vendor $http_x_plex_device_vendor;
proxy_set_header X-Plex-Model $http_x_plex_model;
# Buffering off send to the client as soon as the data is received from Plex.
proxy_redirect off;
proxy_buffering off;
'';
in {
${access.domain} = {
locations."/" = {
proxyPass = access.url;
};
inherit extraConfig;
};
${access.localDomain} = {
local.enable = true;
locations."/" = {
proxyPass = access.url;
};
inherit extraConfig;
}; };
}; };
}; };

View file

@ -1,46 +1,5 @@
{config, ...}: { {...}: {
services = { services.plex.enable = true;
plex = {
enable = true;
};
nginx.virtualHosts = let
extraConfig = ''
# Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause
send_timeout 100m;
# Plex headers
proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier;
proxy_set_header X-Plex-Device $http_x_plex_device;
proxy_set_header X-Plex-Device-Name $http_x_plex_device_name;
proxy_set_header X-Plex-Platform $http_x_plex_platform;
proxy_set_header X-Plex-Platform-Version $http_x_plex_platform_version;
proxy_set_header X-Plex-Product $http_x_plex_product;
proxy_set_header X-Plex-Token $http_x_plex_token;
proxy_set_header X-Plex-Version $http_x_plex_version;
proxy_set_header X-Plex-Nocache $http_x_plex_nocache;
proxy_set_header X-Plex-Provides $http_x_plex_provides;
proxy_set_header X-Plex-Device-Vendor $http_x_plex_device_vendor;
proxy_set_header X-Plex-Model $http_x_plex_model;
# Buffering off send to the client as soon as the data is received from Plex.
proxy_redirect off;
proxy_buffering off;
'';
proxyPass = "http://localhost:32400";
in {
"plex.${config.networking.domain}" = {
locations."/" = {
inherit proxyPass;
};
inherit extraConfig;
};
"plex.local.${config.networking.domain}" = {
local.enable = true;
locations."/" = {
inherit proxyPass;
};
inherit extraConfig;
};
};
};
# Plex Media Server: # Plex Media Server:
# #

View file

@ -9,6 +9,7 @@
nixos.reisen-ct nixos.reisen-ct
nixos.sops nixos.sops
nixos.nginx nixos.nginx
nixos.access.plex
nixos.cloudflared nixos.cloudflared
# media # media