Simplified code and added ports
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.util-nixarr.services.bazarr;
|
||||
in {
|
||||
options = {
|
||||
util-nixarr.services.bazarr = {
|
||||
enable = mkEnableOption "bazarr, a subtitle manager for Sonarr and Radarr";
|
||||
|
||||
package = mkPackageOption pkgs "bazarr" {};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Open ports in the firewall for the bazarr web interface.";
|
||||
};
|
||||
|
||||
listenPort = mkOption {
|
||||
type = types.port;
|
||||
default = 6767;
|
||||
description = "Port on which the bazarr web interface should listen";
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/bazarr";
|
||||
description = "State directory for bazarr";
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "bazarr";
|
||||
description = "User account under which bazarr runs.";
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = "bazarr";
|
||||
description = "Group under which bazarr runs.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0700 bazarr root - -"
|
||||
];
|
||||
|
||||
systemd.services.bazarr = {
|
||||
description = "bazarr";
|
||||
after = ["network.target"];
|
||||
wantedBy = ["multi-user.target"];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
SyslogIdentifier = "bazarr";
|
||||
ExecStart = pkgs.writeShellScript "start-bazarr" ''
|
||||
${pkgs.bazarr}/bin/bazarr \
|
||||
--config '${cfg.dataDir}' \
|
||||
--port ${toString cfg.listenPort} \
|
||||
--no-update True
|
||||
'';
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall = mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [cfg.listenPort];
|
||||
};
|
||||
|
||||
users.users = mkIf (cfg.user == "bazarr") {
|
||||
bazarr = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
};
|
||||
};
|
||||
|
||||
users.groups = mkIf (cfg.group == "bazarr") {
|
||||
bazarr = {};
|
||||
};
|
||||
};
|
||||
}
|
||||
+44
-17
@@ -6,12 +6,9 @@
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.nixarr.bazarr;
|
||||
port = 6767;
|
||||
nixarr = config.nixarr;
|
||||
in {
|
||||
imports = [
|
||||
./bazarr-module
|
||||
];
|
||||
|
||||
options.nixarr.bazarr = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
@@ -24,6 +21,12 @@ in {
|
||||
|
||||
package = mkPackageOption pkgs "bazarr" {};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = port;
|
||||
description = "Port for Bazarr to use.";
|
||||
};
|
||||
|
||||
stateDir = mkOption {
|
||||
type = types.path;
|
||||
default = "${nixarr.stateDir}/bazarr";
|
||||
@@ -74,15 +77,40 @@ in {
|
||||
}
|
||||
];
|
||||
|
||||
util-nixarr.services.bazarr = {
|
||||
enable = cfg.enable;
|
||||
package = cfg.package;
|
||||
user = "bazarr";
|
||||
group = "media";
|
||||
openFirewall = cfg.openFirewall;
|
||||
dataDir = cfg.stateDir;
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0700 bazarr root - -"
|
||||
];
|
||||
|
||||
systemd.services.bazarr = {
|
||||
description = "bazarr";
|
||||
after = ["network.target"];
|
||||
wantedBy = ["multi-user.target"];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = "bazarr";
|
||||
Group = "media";
|
||||
SyslogIdentifier = "bazarr";
|
||||
ExecStart = pkgs.writeShellScript "start-bazarr" ''
|
||||
${pkgs.bazarr}/bin/bazarr \
|
||||
--config '${cfg.stateDir}' \
|
||||
--port ${toString cfg.port} \
|
||||
--no-update True
|
||||
'';
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall = mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [cfg.listenPort];
|
||||
};
|
||||
|
||||
users.users.bazarr = {
|
||||
isSystemUser = true;
|
||||
group = "media";
|
||||
};
|
||||
users.groups.bazarr = {};
|
||||
|
||||
# Enable and specify VPN namespace to confine service in.
|
||||
systemd.services.bazarr.vpnConfinement = mkIf cfg.vpn.enable {
|
||||
enable = true;
|
||||
@@ -90,12 +118,11 @@ in {
|
||||
};
|
||||
|
||||
# Port mappings
|
||||
# TODO: openports
|
||||
vpnNamespaces.wg = mkIf cfg.vpn.enable {
|
||||
portMappings = [
|
||||
{
|
||||
from = config.bazarr.listenPort;
|
||||
to = config.bazarr.listenPort;
|
||||
from = cfg.port;
|
||||
to = cfg.port;
|
||||
}
|
||||
];
|
||||
};
|
||||
@@ -107,17 +134,17 @@ in {
|
||||
recommendedOptimisation = true;
|
||||
recommendedGzipSettings = true;
|
||||
|
||||
virtualHosts."127.0.0.1:${builtins.toString config.bazarr.listenPort}" = {
|
||||
virtualHosts."127.0.0.1:${builtins.toString cfg.port}" = {
|
||||
listen = [
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = config.bazarr.listenPort;
|
||||
port = cfg.port;
|
||||
}
|
||||
];
|
||||
locations."/" = {
|
||||
recommendedProxySettings = true;
|
||||
proxyWebsockets = true;
|
||||
proxyPass = "http://192.168.15.1:${builtins.toString config.bazarr.listenPort}";
|
||||
proxyPass = "http://192.168.15.1:${builtins.toString cfg.port}";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user