-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
Expand file tree
/
Copy pathrqbit.nix
More file actions
151 lines (133 loc) · 3.75 KB
/
rqbit.nix
File metadata and controls
151 lines (133 loc) · 3.75 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{
config,
lib,
pkgs,
...
}:
let
inherit (lib)
mkEnableOption
mkOption
types
mkPackageOption
mkIf
;
cfg = config.services.rqbit;
stateDir = "/var/lib/rqbit";
defaultDownloadDir = "${stateDir}/downloads";
in
{
options.services.rqbit = {
enable = mkEnableOption "rqbit BitTorrent daemon";
package = mkPackageOption pkgs "rqbit" { };
user = mkOption {
type = types.str;
default = "rqbit";
description = "User account under which rqbit runs.";
};
group = mkOption {
type = types.str;
default = "rqbit";
description = "Group account under which rqbit runs.";
};
downloadDir = mkOption {
type = types.path;
default = defaultDownloadDir;
example = "/mnt/storage/torrents";
description = "Directory where to download torrents.";
};
httpPort = mkOption {
type = types.port;
default = 3030;
description = "The listen port for the HTTP API.";
};
httpHost = mkOption {
type = types.str;
default = "127.0.0.1";
example = "0.0.0.0";
description = "The listen host for the HTTP API.";
};
peerPort = mkOption {
type = types.port;
default = 4240;
description = "The port to listen for incoming BitTorrent peer connections (TCP and uTP).";
};
openFirewall = mkEnableOption "opening of the HTTP and Peer ports in the firewall";
};
config = mkIf cfg.enable {
systemd.services.rqbit = {
description = "rqbit BitTorrent Service";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
HOME = stateDir;
RQBIT_HTTP_API_LISTEN_ADDR = "${
if (lib.hasInfix ":" cfg.httpHost) then "[${cfg.httpHost}]" else cfg.httpHost
}:${toString cfg.httpPort}";
RQBIT_LISTEN_PORT = toString cfg.peerPort;
RQBIT_SESSION_PERSISTENCE_LOCATION = stateDir;
};
serviceConfig = {
ExecStart = "${lib.getExe cfg.package} server start ${cfg.downloadDir}";
User = cfg.user;
Group = cfg.group;
StateDirectory = "rqbit";
StateDirectoryMode = "0750";
# systemd-analyze security rqbit
ReadWritePaths = mkIf (cfg.downloadDir != defaultDownloadDir) [ cfg.downloadDir ];
ProtectSystem = "strict";
ProtectHome = "read-only";
PrivateTmp = true;
PrivateDevices = true;
ProtectProc = "invisible";
ProcSubset = "pid";
PrivateUsers = true;
RemoveIPC = true;
CapabilityBoundingSet = "";
NoNewPrivileges = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
ProtectClock = true;
ProtectHostname = true;
RestrictNamespaces = true;
SystemCallFilter = [
"@system-service"
"@network-io"
"@file-system"
"~@privileged"
"~@resources"
];
SystemCallArchitectures = "native";
RestrictRealtime = true;
RestrictSUIDSGID = true;
MemoryDenyWriteExecute = true;
LockPersonality = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_UNIX"
];
UMask = "0027";
};
};
users = {
users = mkIf (cfg.user == "rqbit") {
rqbit = {
inherit (cfg) group;
isSystemUser = true;
};
};
groups = mkIf (cfg.group == "rqbit") { rqbit = { }; };
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [
cfg.httpPort
cfg.peerPort
];
allowedUDPPorts = [ cfg.peerPort ];
};
};
meta.maintainers = with lib.maintainers; [ CodedNil ];
}