-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmagnet.nix
78 lines (68 loc) · 2.08 KB
/
bitmagnet.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ config, lib, ... }:
let
cfg = config.modules.services.bitmagnet;
in
{
options.modules.services.bitmagnet = {
enable = lib.mkEnableOption "BitMagnet Service";
publicApiPort = lib.mkOption {
type = lib.types.int;
default = 3333;
description = "Public API and WebUI port.";
};
publicTorrentPort = lib.mkOption {
type = lib.types.int;
default = 3334;
description = "Public BitTorrent port.";
};
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/bitmagnet";
description = "Directory for storing persistent data.";
};
tmdbApiKey = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "TMDB API key.";
};
runDhtCrawler = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable or disable DHT crawler.";
};
};
config = lib.mkIf cfg.enable {
# Ensure the data directory exists
system.activationScripts.bitmagnet = lib.stringAfter [ "var" ] ''
mkdir -p ${cfg.dataDir}
'';
modules.podgroups.pods.bitmagnet = {
ports = [
"${toString cfg.publicApiPort}:3333"
"${toString cfg.publicTorrentPort}:3334/tcp"
"${toString cfg.publicTorrentPort}:3334/udp"
];
db = {
image = "postgres:17-alpine";
volumes = [ "${cfg.dataDir}/postgres:/var/lib/postgresql/data" ];
environment = {
POSTGRES_PASSWORD = "postgres";
POSTGRES_DB = "bitmagnet";
PGUSER = "postgres";
};
extraOptions = [ "--shm-size=1g" ]; # translate shm_size to extraOptions
};
bitmagnet = {
image = "ghcr.io/bitmagnet-io/bitmagnet:latest";
restartPolicy = "unless-stopped";
environment = {
POSTGRES_HOST = "postgres";
POSTGRES_PASSWORD = "postgres";
TMDB_API_KEY = cfg.tmdbApiKey or "";
};
command = [ "worker" "run" "--keys=http_server" "--keys=queue_server" ]
++ lib.optional cfg.runDhtCrawler "--keys=dht_crawler";
};
};
};
}