Files
nix-config/modules/nixos/services/mediaflow-proxy.nix
2026-09-11 01:59:55 +05:30

120 lines
3.6 KiB
Nix

{
flake.modules.nixos.services = {
config,
lib,
...
}:
with lib; let
cfg = config.tnix.services.mediaflow-proxy;
port = toString cfg.port;
acmeHost = config.tnix.services.nginx.domain;
in {
options.tnix.services.mediaflow-proxy = {
enable = mkEnableOption "MediaFlow Proxy";
host = mkOption {
type = types.str;
default = "0.0.0.0";
description = "Host on which MediaFlow Proxy listens";
};
port = mkOption {
type = types.port;
default = 1113;
description = "Port on which MediaFlow Proxy listens";
};
domain = mkOption {
type = types.str;
default = "";
description = "Domain on which MediaFlow Proxy is available";
};
configureNginx = mkOption {
type = types.bool;
default = false;
description = "Whether to configure Nginx as a reverse proxy for MediaFlow Proxy";
};
configurePangolin = mkOption {
type = types.bool;
default = false;
description = "Whether to configure Pangolin as a reverse proxy for MediaFlow Proxy";
};
image = mkOption {
type = types.str;
default = "ghcr.io/mhdzumair/mediaflow-proxy-light:latest";
description = "Container image to use";
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
description = "Environment file with secrets passed to the container";
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = !cfg.configureNginx || cfg.domain != "";
message = "tnix.services.mediaflow-proxy.domain must be set when tnix.services.mediaflow-proxy.configureNginx is enabled.";
}
{
assertion = !cfg.configurePangolin || cfg.domain != "";
message = "tnix.services.mediaflow-proxy.domain must be set when tnix.services.mediaflow-proxy.configurePangolin is enabled.";
}
];
virtualisation.oci-containers.containers.mediaflow-proxy = {
image = cfg.image;
ports = [
"${cfg.host}:${port}:${port}"
];
environment = {
APP__SERVER__HOST = "0.0.0.0";
APP__SERVER__PORT = port;
};
environmentFiles = optional (cfg.environmentFile != null) cfg.environmentFile;
};
services = {
nginx.virtualHosts.${cfg.domain} = mkIf cfg.configureNginx {
forceSSL = acmeHost != "";
useACMEHost = mkIf (acmeHost != "") acmeHost;
locations."/" = {
proxyPass = "http://${cfg.host}:${port}";
proxyWebsockets = true;
};
};
newt.blueprint.proxy-resources = mkIf cfg.configurePangolin {
mediaflow-proxy = {
auth = {
sso-enabled = false;
};
full-domain = cfg.domain;
name = "mediaflow-proxy";
protocol = "http";
targets = [
{
hostname = "localhost";
method = "http";
port = cfg.port;
healthcheck = {
hostname = "localhost";
port = cfg.port;
scheme = "http";
method = "GET";
path = "/";
};
}
];
};
};
};
};
};
}