56 lines
1.6 KiB
Nix
56 lines
1.6 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
...
|
|
}: let
|
|
inherit (lib.modules) mkIf;
|
|
|
|
cfg = config.services.piped;
|
|
in {
|
|
config = mkIf (cfg.enable && !cfg.disableProxy) {
|
|
systemd.services.piped-proxy = {
|
|
wantedBy = ["multi-user.target"];
|
|
environment.BIND = "0.0.0.0:${toString cfg.internalProxyPort}";
|
|
environment.IPV4_ONLY = mkIf cfg.proxyIPv4Only "1";
|
|
serviceConfig = {
|
|
ExecStart = "${cfg.proxyPackage}/bin/piped-proxy";
|
|
|
|
RestartSec = "5s";
|
|
User = "piped";
|
|
|
|
CapabilityBoundingSet = "";
|
|
PrivateDevices = true;
|
|
PrivateUsers = true;
|
|
ProtectHome = true;
|
|
ProtectKernelLogs = true;
|
|
ProtectProc = "invisible";
|
|
RestrictAddressFamilies = ["AF_UNIX" "AF_INET" "AF_INET6"];
|
|
RestrictNamespaces = true;
|
|
SystemCallArchitectures = "native";
|
|
SystemCallFilter = ["@system-service" "~@privileged" "~@resources"];
|
|
};
|
|
};
|
|
|
|
services.nginx.virtualHosts."${cfg.proxyDomain}" = mkIf (!cfg.disableNginx) {
|
|
forceSSL = cfg.nginxForceSSL;
|
|
enableACME = cfg.nginxEnableACME;
|
|
locations."/" = {
|
|
proxyPass = "http://localhost:${toString cfg.internalProxyPort}";
|
|
extraConfig =
|
|
cfg.proxyNginxExtraConfig
|
|
+ ''
|
|
add_header Cache-Control "public, max-age=604800";
|
|
'';
|
|
};
|
|
locations."~ (/videoplayback|/api/v4/|/api/manifest/)" = {
|
|
proxyPass = "http://localhost:${toString cfg.internalProxyPort}";
|
|
extraConfig =
|
|
cfg.proxyNginxExtraConfig
|
|
+ ''
|
|
add_header Cache-Control private always;
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|