Added cross-seed support, still untested

This commit is contained in:
rasmus-kirk
2024-03-01 12:24:17 +01:00
parent bd37178c70
commit a168966644
4 changed files with 131 additions and 46 deletions
-1
View File
@@ -63,7 +63,6 @@
packages = { packages = {
docs = pkgs.callPackage ./mkDocs.nix {inherit inputs;}; docs = pkgs.callPackage ./mkDocs.nix {inherit inputs;};
pandoc = pkgs.callPackage ./mkPandoc.nix {inherit inputs;};
}; };
devshells.default = { devshells.default = {
+6 -6
View File
@@ -41,12 +41,12 @@ in {
''; '';
}; };
config = mkIf cfg.vpn.enable { config = mkIf cfg.expose.vpn.enable {
assertions = [ assertions = [
{ {
assertion = cfg.vpn.enable -> nixarr.vpn.enable; assertion = cfg.expose.vpn.enable -> nixarr.vpn.enable;
message = '' message = ''
The nixarr.openssh.vpn.enable option requires the The nixarr.openssh.expose.vpn.enable option requires the
nixarr.vpn.enable option to be set, but it was not. nixarr.vpn.enable option to be set, but it was not.
''; '';
} }
@@ -54,9 +54,9 @@ in {
warnings = if config.services.openssh.enable then [ warnings = if config.services.openssh.enable then [
'' ''
nixarr.openssh.vpn.enable is set, but openssh is not enabled on your nixarr.openssh.expose.vpn.enable is set, but openssh is not enabled
system, so the openssh server is not running. This is probably not on your system, so the openssh server is not running. This is probably
what you wanted. You can add the following lines to enable it: not what you wanted. You can add the following lines to enable it:
services.openssh = { services.openssh = {
enable = true; enable = true;
+22 -9
View File
@@ -6,19 +6,23 @@
}: }:
with lib; let with lib; let
cfg = config.util-nixarr.services.cross-seed; cfg = config.util-nixarr.services.cross-seed;
#settingsFormat = pkgs.formats.json {}; settingsFormat = pkgs.formats.json {};
#settingsFile = settingsFormat.generate "settings.json" cfg.settings; settingsFile = settingsFormat.generate "settings.json" cfg.settings;
cross-seedPkg = import ../../../pkgs/cross-seed { inherit (pkgs) stdenv lib fetchFromGitHub; }; cross-seedPkg = import ../../../pkgs/cross-seed { inherit (pkgs) stdenv lib fetchFromGitHub; };
in { in {
options = { options = {
util-nixarr.services.cross-seed = { util-nixarr.services.cross-seed = {
enable = mkEnableOption "cross-seed"; enable = mkEnableOption "cross-seed";
configFile = mkOption { settings = mkOption {
type = with types; nullOr path; type = types.attrs;
default = null; default = {};
example = "/var/lib/secrets/cross-seed/settings.js"; example = ''
description = "cross-seed config file"; # TODO: todo {
delay = 10;
}
'';
description = "cross-seed config"; # TODO: todo
}; };
dataDir = mkOption { dataDir = mkOption {
@@ -27,6 +31,12 @@ in {
description = "cross-seed dataDir"; # TODO: todo description = "cross-seed dataDir"; # TODO: todo
}; };
credentialsFile = mkOption {
type = types.path;
default = "/run/secrets/cross-seed/credentialsFile.json";
description = "cross-seed dataDir"; # TODO: todo
};
user = mkOption { user = mkOption {
type = types.str; type = types.str;
default = "cross-seed"; default = "cross-seed";
@@ -54,9 +64,12 @@ in {
environment.CONFIG_DIR = cfg.dataDir; environment.CONFIG_DIR = cfg.dataDir;
serviceConfig = { serviceConfig = {
# Run as root in case that the cfg.credentialsFile is not readable by cross-seed
ExecStartPre = [("+" + pkgs.writeShellScript "transmission-prestart" '' ExecStartPre = [("+" + pkgs.writeShellScript "transmission-prestart" ''
mv ${cfg.configFile} ${cfg.dataDir} ${pkgs.jq}/bin/jq --slurp add ${settingsFile} '${cfg.credentialsFile}' |
'')]; install -D -m 600 -o '${cfg.user}' /dev/stdin '${cfg.dataDir}/config.json'
''
)];
Type = "simple"; Type = "simple";
User = cfg.user; User = cfg.user;
Group = cfg.group; Group = cfg.group;
+103 -30
View File
@@ -1,4 +1,3 @@
# TODO: Dir creation and file permissions in nix
{ {
config, config,
lib, lib,
@@ -9,19 +8,41 @@ with lib; let
cfg = config.nixarr.transmission; cfg = config.nixarr.transmission;
nixarr = config.nixarr; nixarr = config.nixarr;
dnsServers = config.lib.vpn.dnsServers; dnsServers = config.lib.vpn.dnsServers;
get-indexers = with builtins; pkgs.writeShellApplication { cfg-cross-seed = config.nixarr.transmission.privateTrackers.cross-seed;
name = "get-indexers"; transmissionCrossSeedScript = with builtins; pkgs.writeShellApplication {
name = "mk-cross-seed-credentials";
runtimeInputs = with pkgs; [ curl ];
text = ''
curl -XPOST http://localhost:2468/api/webhook?apikey=YOUR_API_KEY --data-urlencode "infoHash=$TR_TORRENT_HASH"
'';
};
mkCrossSeedCredentials = with builtins; pkgs.writeShellApplication {
name = "mk-cross-seed-credentials";
runtimeInputs = with pkgs; [ jq yq ]; runtimeInputs = with pkgs; [ jq yq ];
text = '' text =
PROWLARR_API_KEY=$(xq '.Config.ApiKey' "${nixarr.prowlarr.stateDir}/config.xml") "INDEX_LINKS=("
'' + strings.concatMapStringsSep " " toString cfg.privateTrackers.cross-seed.indexIds
+ toJson ( + ")"
map (x: ''
''http://localhost:9696/${toString x}/api?apikey="$PROWLARR_API_KEY"'' TMP_JSON=$(mktemp)
) cfg.privateTrackers.cross-seed.indexIds CRED_FILE="/run/secrets/cross-seed/credentialsFile.json"
); PROWLARR_API_KEY=$(xq '.Config.ApiKey' "${nixarr.prowlarr.stateDir}/config.xml")
CRED_DIR=$(dirname "$filePath")
echo '{}' > "$CRED_FILE"
chmod 400 "$CRED_FILE"
chown "${config.util-nixarr.services.cross-seed.user}" "$CRED_FILE"
for i in "''${INDEX_LINKS[@]}"
do
LINK="http://localhost:9696/$i/api?apikey=$PROWLARR_API_KEY"
jq ".torznab += [\"$LINK\"]" "$CRED_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$CRED_FILE"
done
'';
}; };
in { in {
options.nixarr.transmission = { options.nixarr.transmission = {
@@ -69,19 +90,47 @@ in {
their rules ¯\\_()_/¯. their rules ¯\\_()_/¯.
''; '';
}; };
cross-seed = { cross-seed = {
enable = mkOption { enable = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = '' description = ''
Enable the cross-seed service. **Required options:** [`nixarr.prowlarr.enable`](#nixarr.prowlarr.enable)
Whether or not to enable the [cross-seed](https://www.cross-seed.org/) service.
''; '';
}; };
stateDir = mkOption {
type = types.path;
default = "${nixarr.stateDir}/nixarr/cross-seed";
description = ''
The state directory for Transmission.
'';
};
indexIds = mkOption { indexIds = mkOption {
type = with types; listOf int; type = with types; listOf int;
default = []; default = [];
description = '' description = ''
list of indexers TODO: todo List of indexer-ids, from prowlarr. These are from the RSS links
for the indexers, located by the "radio" or "RSS" logo on the
right of the indexer, you'll see the links have the form:
`http://localhost:9696/1/api?apikey=aaaaaaaaaaaaa`
Then the id needed here is the `1`.
'';
};
extraSettings = mkOption {
type = types.attrs;
default = {};
description = ''
Extra settings for the cross-seed
service, see [the cross-seed options
documentation](https://www.cross-seed.org/docs/basics/options)
''; '';
}; };
}; };
@@ -113,7 +162,7 @@ in {
description = "Transmission web-UI port."; description = "Transmission web-UI port.";
}; };
extraConfig = mkOption { extraSettings = mkOption {
type = types.attrs; type = types.attrs;
default = {}; default = {};
description = '' description = ''
@@ -140,9 +189,10 @@ in {
''; '';
} }
{ {
assertion = cfg.privateTrackers.cross-seed.enable -> nixarr.prowlarr.enable; assertion = cfg-cross-seed.enable -> nixarr.prowlarr.enable;
message = '' message = ''
TODO: todo The nixarr.privateTrackers.cross-seed.enable option requires the
nixarr.prowlarr.enable option to be set, but it was not.
''; '';
} }
]; ];
@@ -151,7 +201,34 @@ in {
"d '${cfg.stateDir}' 0700 torrenter root - -" "d '${cfg.stateDir}' 0700 torrenter root - -"
# 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' 0700 torrenter root - -"
]; ] ++ (
if cfg-cross-seed.enable then
[ "d '${cfg-cross-seed.stateDir}' 0700 cross-seed root - -" ]
else []
);
util-nixarr.services.cross-seed = mkIf cfg-cross-seed.enable {
enable = true;
dataDir = cfg-cross-seed.stateDir;
#group = "media";
settings = {
torrentDir = "${nixarr.mediaDir}/torrents";
outputDir = "${nixarr.mediaDir}/torrents/cross-seed";
transmissionRpcUrl = "http://transmission:${builtins.toString cfg.uiPort}/transmission/rpc";
rssCadence = "20 minutes";
# Enable infrequent periodic searches
searchCadence = "1 week";
excludeRecentSearch = "1 year";
excludeOlder = "1 year";
} // cfg-cross-seed.extraSettings;
};
# Run as root in case that the cfg.credentialsFile is not readable by cross-seed
systemd.services.cross-seed.serviceConfig = mkIf cfg-cross-seed.enable {
ExecStartPre = [(mkBefore
("+" + (getExe mkCrossSeedCredentials))
)];
};
services.transmission = mkIf (!cfg.vpn.enable) { services.transmission = mkIf (!cfg.vpn.enable) {
enable = true; enable = true;
@@ -183,8 +260,8 @@ in {
blocklist-url = "https://github.com/Naunter/BT_BlockLists/raw/master/bt_blocklists.gz"; blocklist-url = "https://github.com/Naunter/BT_BlockLists/raw/master/bt_blocklists.gz";
peer-port = cfg.peerPort; peer-port = cfg.peerPort;
dht-enabled = !cfg.privateTrackers; dht-enabled = !cfg.privateTrackers.disableDhtPex;
pex-enabled = !cfg.privateTrackers; pex-enabled = !cfg.privateTrackers.disableDhtPex;
utp-enabled = false; utp-enabled = false;
encryption = 1; encryption = 1;
port-forwarding-enabled = false; port-forwarding-enabled = false;
@@ -192,6 +269,9 @@ in {
anti-brute-force-enabled = true; anti-brute-force-enabled = true;
anti-brute-force-threshold = 10; anti-brute-force-threshold = 10;
script-torrent-done-enabled = true;
script-torrent-done-filename = getExe transmissionCrossSeedScript;
message-level = message-level =
if cfg.messageLevel == "none" if cfg.messageLevel == "none"
then 0 then 0
@@ -209,14 +289,7 @@ in {
then 6 then 6
else null; else null;
} }
// cfg.extraConfig; // cfg.extraSettings;
};
services.cross-seed = mkIf cfg.cross-seed.enable {
enable = true;
group = "media";
dataDir = cfg.privateTrackers.cross-seed.dataDir;
configFile = cfg.privateTrackers.cross-seed.configFile;
}; };
util-nixarr.vpnnamespace = mkIf cfg.vpn.enable { util-nixarr.vpnnamespace = mkIf cfg.vpn.enable {
@@ -297,8 +370,8 @@ in {
blocklist-url = "https://github.com/Naunter/BT_BlockLists/raw/master/bt_blocklists.gz"; blocklist-url = "https://github.com/Naunter/BT_BlockLists/raw/master/bt_blocklists.gz";
peer-port = cfg.peerPort; peer-port = cfg.peerPort;
dht-enabled = !cfg.privateTrackers; dht-enabled = !cfg.privateTrackers.disableDhtPex;
pex-enabled = !cfg.privateTrackers; pex-enabled = !cfg.privateTrackers.disableDhtPex;
utp-enabled = false; utp-enabled = false;
encryption = 1; encryption = 1;
port-forwarding-enabled = false; port-forwarding-enabled = false;
@@ -309,7 +382,7 @@ in {
# 0 = None, 1 = Critical, 2 = Error, 3 = Warn, 4 = Info, 5 = Debug, 6 = Trace # 0 = None, 1 = Critical, 2 = Error, 3 = Warn, 4 = Info, 5 = Debug, 6 = Trace
message-level = 3; message-level = 3;
} }
// cfg.extraConfig; // cfg.extraSettings;
}; };
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [