Fixed bazarr and cross-seed

This commit is contained in:
rasmus-kirk
2024-03-12 17:28:21 +01:00
parent ec656712e2
commit 39f6357a0a
6 changed files with 115 additions and 26 deletions
+85
View File
@@ -0,0 +1,85 @@
{ 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");
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 = {};
};
};
}
+5 -5
View File
@@ -7,6 +7,10 @@ with lib; let
cfg = config.nixarr.bazarr; cfg = config.nixarr.bazarr;
nixarr = config.nixarr; nixarr = config.nixarr;
in { in {
imports = [
./bazarr-module
];
options.nixarr.bazarr = { options.nixarr.bazarr = {
enable = mkEnableOption "the bazarr service."; enable = mkEnableOption "the bazarr service.";
@@ -41,11 +45,7 @@ in {
} }
]; ];
systemd.tmpfiles.rules = [ util-nixarr.services.bazarr = {
"d '${cfg.stateDir}' 0700 bazarr root - -"
];
services.bazarr = {
enable = cfg.enable; enable = cfg.enable;
user = "bazarr"; user = "bazarr";
group = "media"; group = "media";
+10 -5
View File
@@ -14,7 +14,7 @@ with lib; let
# Thanks chatgpt... # Thanks chatgpt...
text = '' text = ''
# Path to the JSON file # Path to the JSON file
json_file="${cfg.njalla.keysFile}" json_file="$1"
# Convert the JSON object into a series of tab-separated key-value pairs using jq # Convert the JSON object into a series of tab-separated key-value pairs using jq
# - `to_entries[]`: Convert the object into an array of key-value pairs. # - `to_entries[]`: Convert the object into an array of key-value pairs.
@@ -120,7 +120,7 @@ in {
{ {
assertion = cfg.njalla.vpn.enable -> ( assertion = cfg.njalla.vpn.enable -> (
cfg.njalla.vpn.keysFile != null && cfg.njalla.vpn.keysFile != null &&
nixarr.vpn.enable config.nixarr.vpn.enable
); );
message = '' message = ''
The nixarr.ddns.njalla.enable option requires the The nixarr.ddns.njalla.enable option requires the
@@ -166,17 +166,22 @@ in {
description = "Sets the Njalla DDNS records"; description = "Sets the Njalla DDNS records";
serviceConfig = { serviceConfig = {
ExecStart = getExe ddns-njalla; ExecStart = ''${getExe ddns-njalla} "${cfg.njalla.keysFile}"'';
Type = "oneshot"; Type = "oneshot";
}; };
}; };
}) })
(mkIf cfg.njalla.vpn.enable { (mkIf (cfg.njalla.vpn.enable && config.nixarr.vpn.enable) {
ddnsNjallaVpn = { ddnsNjallaVpn = {
description = "Sets the Njalla DDNS records over VPN"; description = "Sets the Njalla DDNS records over VPN";
vpnconfinement = {
enable = true;
vpnnamespace = "wg";
};
serviceConfig = { serviceConfig = {
ExecStart = getExe ddns-njalla; ExecStart = ''${getExe ddns-njalla} "${cfg.njalla.vpn.keysFile}"'';
Type = "oneshot"; Type = "oneshot";
}; };
}; };
+5 -4
View File
@@ -244,10 +244,11 @@ in with lib; {
# Port mappings # Port mappings
# TODO: openports if expose.vpn # TODO: openports if expose.vpn
vpnnamespaces.wg = mkIf cfg.vpn.enable { vpnnamespaces.wg = mkIf cfg.vpn.enable {
portMappings = [{ From = defaultPort; To = defaultPort; }]; portMappings = [{ from = defaultPort; to = defaultPort; }];
openVPNPorts = optionalString cfg.expose.vpn.enable [ openVPNPorts = optional cfg.expose.vpn.enable {
{ port = cfg.expose.vpn.port; protocol = "tcp"; } port = cfg.expose.vpn.port;
]; protocol = "tcp";
};
}; };
}; };
} }
+4 -3
View File
@@ -207,9 +207,10 @@ in {
# TODO: wtf to do about openports # TODO: wtf to do about openports
vpnnamespaces.wg = mkIf cfg.vpn.enable { vpnnamespaces.wg = mkIf cfg.vpn.enable {
enable = true; enable = true;
openVPNPorts = optionalList cfg.vpn.vpnTestService.enable [ openVPNPorts = optional cfg.vpn.vpnTestService.enable {
{ port = cfg.vpn.vpnTestService.port; protocol = "tcp"; } port = cfg.vpn.vpnTestService.port;
]; protocol = "tcp";
};
accessibleFrom = [ accessibleFrom = [
"192.168.1.0/24" "192.168.1.0/24"
"127.0.0.1" "127.0.0.1"
+6 -9
View File
@@ -224,19 +224,16 @@ in {
]; ];
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d '${cfg.stateDir}' 0700 torrenter root - -" "d '${cfg.stateDir}' 0750 torrenter torrenter - -"
# This is fixes a bug in nixpks (https://github.com/NixOS/nixpkgs/issues/291883) # This is fixes a bug in nixpks (https://github.com/NixOS/nixpkgs/issues/291883)
"d '${cfg.stateDir}/.config/transmission-daemon' 0700 torrenter root - -" "d '${cfg.stateDir}/.config/transmission-daemon' 0750 torrenter torrenter - -"
] ++ ( ] ++ optional cfg-cross-seed.enable
if cfg-cross-seed.enable then "d '${cfg-cross-seed.stateDir}' 0700 cross-seed root - -";
[ "d '${cfg-cross-seed.stateDir}' 0700 cross-seed root - -" ]
else []
);
util-nixarr.services.cross-seed = mkIf cfg-cross-seed.enable { util-nixarr.services.cross-seed = mkIf cfg-cross-seed.enable {
enable = true; enable = true;
dataDir = cfg-cross-seed.stateDir; dataDir = cfg-cross-seed.stateDir;
#group = "media"; group = "torrenter";
settings = { settings = {
torrentDir = "${nixarr.mediaDir}/torrents"; torrentDir = "${nixarr.mediaDir}/torrents";
outputDir = "${nixarr.mediaDir}/torrents/.cross-seed"; outputDir = "${nixarr.mediaDir}/torrents/.cross-seed";
@@ -336,7 +333,7 @@ in {
# Port mappings # Port mappings
vpnnamespaces.wg = mkIf cfg.vpn.enable { vpnnamespaces.wg = mkIf cfg.vpn.enable {
portMappings = [{ From = cfg.uiPort; To = cfg.uiPort; }]; portMappings = [{ from = cfg.uiPort; to = cfg.uiPort; }];
openVPNPorts = [ openVPNPorts = [
{ port = cfg.peerPort; protocol = "both"; } { port = cfg.peerPort; protocol = "both"; }
]; ];