-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransmission.nix
124 lines (104 loc) · 3 KB
/
transmission.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
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
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.custom.transmission;
staticFiles = "${pkgs.transmission}/share/transmission/web/";
in
{
options.custom.transmission = {
enable = mkOption {
default = false;
example = true;
};
domain = mkOption {
type = types.str;
};
download-dir = mkOption {
type = types.str;
};
incomplete-dir = mkOption {
type = types.str;
};
port = mkOption {
type = types.port;
default = 51413;
};
basicAuthFile = mkOption {
type = types.str;
example = "/run/agenix/transmission-auth";
};
namespace = mkOption {
type = types.nullOr types.str;
default = null;
};
rpc-whitelist = mkOption {
type = types.str;
default = "127.0.0.1";
};
rpc-bind-address = mkOption {
type = types.str;
default = "127.0.0.1";
};
};
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ cfg.port ];
networking.firewall.allowedUDPPorts = [ cfg.port ];
services.transmission = {
enable = true;
settings = {
peer-port = cfg.port;
download-dir = cfg.download-dir;
incomplete-dir = cfg.incomplete-dir;
encryption = 2;
rpc-url = "/";
rpc-bind-address = cfg.rpc-bind-address;
rpc-host-whitelist-enabled = false;
rpc-whitelist = cfg.rpc-whitelist;
};
openPeerPorts = true;
};
systemd.services.transmission.serviceConfig.NetworkNamespacePath= mkIf (cfg.namespace != null) "/var/run/netns/${cfg.namespace}";
users.users.nginx.extraGroups = [ "transmission" ];
services.nginx.virtualHosts."${cfg.domain}" = {
# calculate base domain
useACMEHost = (head (elemAt (builtins.split ''([^.]*\.[^.]*$)'' cfg.domain) 1));
forceSSL = true;
basicAuthFile = cfg.basicAuthFile;
extraConfig = "
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Connection \"\";
proxy_pass_header X-Transmission-Session-Id;
add_header Front-End-Https on;
";
locations."/" = {
return = "302 http://\$server_name/web";
};
locations."/rpc" = {
proxyPass = "http://${cfg.rpc-bind-address}:9091";
};
locations."/web/" = {
proxyPass = "http://${cfg.rpc-bind-address}:9091";
};
locations."/upload" = {
proxyPass = "http://${cfg.rpc-bind-address}:9091";
};
locations."/web/style/" = {
alias = "${staticFiles}/style/";
};
locations."/web/javascript/" = {
alias = "${staticFiles}/javascript/";
};
locations."/web/images/" = {
alias = "${staticFiles}/images/";
};
locations."/downloaded-files/" = {
alias = "${cfg.download-dir}/";
extraConfig = "autoindex on;";
};
};
};
}