nixos-config/modules/media-proxy.nix

49 lines
1.3 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
let
port = 8888;
services = {
2021-01-06 13:09:29 +01:00
"media" = config.krops.secrets.media-proxy-auth.path;
"torrent" = config.krops.secrets.torrent-proxy-auth.path;
};
in
{
options.sbruder.media-proxy.enable = lib.mkEnableOption "media proxy";
2021-01-06 13:09:29 +01:00
config = lib.mkIf config.sbruder.media-proxy.enable {
krops.secrets = {
torrent-proxy-auth.group = "nginx";
media-proxy-auth.group = "nginx";
};
users.users.nginx.extraGroups = [ "keys" ];
services.nginx = {
enable = true;
virtualHosts.media-proxy = {
serverName = "localhost";
listen = [
{ inherit port; addr = "127.0.0.1"; }
{ inherit port; addr = "[::1]"; }
];
locations = {
"/".extraConfig = ''
2021-03-05 16:12:25 +01:00
rewrite ^/__nginx-interactive-index-assets__/(.*)$ /media/__nginx-interactive-index-assets__/$1;
2021-01-06 13:09:29 +01:00
'';
} // lib.mapAttrs'
(name: secret: {
name = "/${name}/";
value = {
proxyPass = "https://${name}.sbruder.de/";
proxyWebsockets = true;
extraConfig = ''
proxy_buffering off;
include ${secret};
charset utf-8;
'';
};
})
services;
};
};
};
}