Skip to content

Commit

Permalink
Fixed bazarr and cross-seed
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-kirk committed Mar 12, 2024
1 parent ec65671 commit 39f6357
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 26 deletions.
85 changes: 85 additions & 0 deletions nixarr/bazarr/bazarr-module/default.nix
Original file line number Diff line number Diff line change
@@ -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 = {};
};
};
}
10 changes: 5 additions & 5 deletions nixarr/bazarr/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ with lib; let
cfg = config.nixarr.bazarr;
nixarr = config.nixarr;
in {
imports = [
./bazarr-module
];

options.nixarr.bazarr = {
enable = mkEnableOption "the bazarr service.";

Expand Down Expand Up @@ -41,11 +45,7 @@ in {
}
];

systemd.tmpfiles.rules = [
"d '${cfg.stateDir}' 0700 bazarr root - -"
];

services.bazarr = {
util-nixarr.services.bazarr = {
enable = cfg.enable;
user = "bazarr";
group = "media";
Expand Down
15 changes: 10 additions & 5 deletions nixarr/ddns/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with lib; let
# Thanks chatgpt...
text = ''
# 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
# - `to_entries[]`: Convert the object into an array of key-value pairs.
Expand Down Expand Up @@ -120,7 +120,7 @@ in {
{
assertion = cfg.njalla.vpn.enable -> (
cfg.njalla.vpn.keysFile != null &&
nixarr.vpn.enable
config.nixarr.vpn.enable
);
message = ''
The nixarr.ddns.njalla.enable option requires the
Expand Down Expand Up @@ -166,17 +166,22 @@ in {
description = "Sets the Njalla DDNS records";

serviceConfig = {
ExecStart = getExe ddns-njalla;
ExecStart = ''${getExe ddns-njalla} "${cfg.njalla.keysFile}"'';
Type = "oneshot";
};
};
})
(mkIf cfg.njalla.vpn.enable {
(mkIf (cfg.njalla.vpn.enable && config.nixarr.vpn.enable) {
ddnsNjallaVpn = {
description = "Sets the Njalla DDNS records over VPN";

vpnconfinement = {
enable = true;
vpnnamespace = "wg";
};

serviceConfig = {
ExecStart = getExe ddns-njalla;
ExecStart = ''${getExe ddns-njalla} "${cfg.njalla.vpn.keysFile}"'';
Type = "oneshot";
};
};
Expand Down
9 changes: 5 additions & 4 deletions nixarr/jellyfin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,11 @@ in with lib; {
# Port mappings
# TODO: openports if expose.vpn
vpnnamespaces.wg = mkIf cfg.vpn.enable {
portMappings = [{ From = defaultPort; To = defaultPort; }];
openVPNPorts = optionalString cfg.expose.vpn.enable [
{ port = cfg.expose.vpn.port; protocol = "tcp"; }
];
portMappings = [{ from = defaultPort; to = defaultPort; }];
openVPNPorts = optional cfg.expose.vpn.enable {
port = cfg.expose.vpn.port;
protocol = "tcp";
};
};
};
}
7 changes: 4 additions & 3 deletions nixarr/nixarr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ in {
# TODO: wtf to do about openports
vpnnamespaces.wg = mkIf cfg.vpn.enable {
enable = true;
openVPNPorts = optionalList cfg.vpn.vpnTestService.enable [
{ port = cfg.vpn.vpnTestService.port; protocol = "tcp"; }
];
openVPNPorts = optional cfg.vpn.vpnTestService.enable {
port = cfg.vpn.vpnTestService.port;
protocol = "tcp";
};
accessibleFrom = [
"192.168.1.0/24"
"127.0.0.1"
Expand Down
15 changes: 6 additions & 9 deletions nixarr/transmission/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,16 @@ in {
];

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)
"d '${cfg.stateDir}/.config/transmission-daemon' 0700 torrenter root - -"
] ++ (
if cfg-cross-seed.enable then
[ "d '${cfg-cross-seed.stateDir}' 0700 cross-seed root - -" ]
else []
);
"d '${cfg.stateDir}/.config/transmission-daemon' 0750 torrenter torrenter - -"
] ++ optional cfg-cross-seed.enable
"d '${cfg-cross-seed.stateDir}' 0700 cross-seed root - -";

util-nixarr.services.cross-seed = mkIf cfg-cross-seed.enable {
enable = true;
dataDir = cfg-cross-seed.stateDir;
#group = "media";
group = "torrenter";
settings = {
torrentDir = "${nixarr.mediaDir}/torrents";
outputDir = "${nixarr.mediaDir}/torrents/.cross-seed";
Expand Down Expand Up @@ -336,7 +333,7 @@ in {

# Port mappings
vpnnamespaces.wg = mkIf cfg.vpn.enable {
portMappings = [{ From = cfg.uiPort; To = cfg.uiPort; }];
portMappings = [{ from = cfg.uiPort; to = cfg.uiPort; }];
openVPNPorts = [
{ port = cfg.peerPort; protocol = "both"; }
];
Expand Down

0 comments on commit 39f6357

Please sign in to comment.