-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud-server.nix
166 lines (158 loc) · 4.52 KB
/
cloud-server.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{ lib, config, pkgs, ... }:
let
cfg = config.my.services;
anythingEnabled = (cfg.plex || cfg.calibre || cfg.nextCloud);
in
with lib;
{
options.my.services = {
plex = mkEnableOption {};
calibre = mkEnableOption {};
nextCloud = mkEnableOption {};
anki = mkEnableOption {};
webDomain = mkOption { type = types.str; };
mediaRoot = mkOption { type = types.str; };
adminEmail = mkOption { type = types.str; };
adminPasswordFile = mkOption { type = types.str; };
};
config = mkMerge [
# Base
(mkIf anythingEnabled {
users.extraGroups = {
media = {};
};
networking.firewall = {
allowedTCPPorts = [ 80 443 ];
};
security.acme = {
acceptTerms = true;
defaults.email = cfg.adminEmail;
};
services.nginx = {
enable = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts = {
"${cfg.webDomain}" = {
forceSSL = true;
enableACME = true;
};
};
};
})
# Plex
(mkIf cfg.plex {
services.plex = {
enable = true;
openFirewall = true;
dataDir = "${cfg.mediaRoot}/.plex";
};
users.extraUsers.plex.extraGroups = [ "media" ];
environment.systemPackages = with pkgs; [
sqlite
];
})
# Calibre
(mkIf cfg.calibre {
services.nginx = {
virtualHosts =
{"${cfg.webDomain}" = {
locations."/calibre" = {
proxyPass = "http://127.0.0.1:8083/";
root = "/var/www/calibre";
extraConfig =
"proxy_busy_buffers_size 1024k;" +
"proxy_buffers 4 512k;" +
"proxy_buffer_size 1024k;" +
"proxy_set_header X-Script-Name /calibre;" +
"proxy_set_header X-Scheme $scheme;";
};
};
};
};
services.calibre-server = {
enable = false;
libraries = [
"${cfg.mediaRoot}/Ebooks"
];
};
services.calibre-web = {
enable = true;
openFirewall = true;
listen.ip = "127.0.0.1";
options = {
enableBookUploading = true;
enableBookConversion = true;
calibreLibrary = "${cfg.mediaRoot}/Ebooks";
};
};
users.extraUsers.calibre-web.extraGroups = [ "media" ];
#users.extraUsers.calibre-server.extraGroups = [ "media" ];
environment.systemPackages = with pkgs; [
calibre
];
})
# Anki
(mkIf cfg.anki {
services.ankisyncd = {
enable = false;
host = "127.0.0.1";
port = 27701;
openFirewall = true;
#users = [{username = "adminhraidstn";
# password = "passwordhraidstn";}];
};
services.nginx = {
virtualHosts = {
"${cfg.webDomain}" = {
locations."/anki" = {
proxyPass = "http://127.0.0.1:27701/";
root = "/var/www/anki";
extraConfig = ''
proxy_http_version 1.0;
proxy_set_header X-Script-Name /anki;
proxy_set_header X-Scheme $scheme;
client_max_body_size 222M;
'';
};
};
};
};
})
# NextCloud
(mkIf cfg.nextCloud {
services.nginx = {
virtualHosts =
{
"localhost" = {
listen = [ { addr = "127.0.0.1"; port = 8080; } ];
};
"${cfg.webDomain}" = {
locations."/nextcloud" = {
proxyPass = "http://127.0.0.1:8080/";
root = "/var/www/nextcloud";
extraConfig =
"proxy_set_header X-Script-Name /nextcloud;" +
"proxy_set_header X-Scheme $scheme;";
};
};
};
};
services.nextcloud = {
enable = true;
package = pkgs.nextcloud25;
hostName = "localhost";
extraApps = with pkgs.nextcloud25Packages.apps; {
inherit mail news contacts deck files_texteditor keeweb notes onlyoffice tasks twofactor_totp notify_push;
};
extraAppsEnable = true;
enableBrokenCiphersForSSE = false;
config.adminpassFile = cfg.adminPasswordFile;
extraOptions = {
mail_smtpmode = "sendmail";
mail_sendmailmode = "pipe";
};
};
})
];
}