]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/tools/tools/default.nix
Add Tinc VPN
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / tools / default.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
10889174 2let
4288c2f2
IB
3 adminer = pkgs.callPackage ./adminer.nix {
4 inherit (pkgs.webapps) adminer;
5 };
6 ympd = pkgs.callPackage ./ympd.nix {
ab8f306d 7 env = config.myEnv.tools.ympd;
4288c2f2
IB
8 };
9 ttrss = pkgs.callPackage ./ttrss.nix {
10 inherit (pkgs.webapps) ttrss ttrss-plugins;
ab8f306d 11 env = config.myEnv.tools.ttrss;
4288c2f2 12 };
4288c2f2 13 kanboard = pkgs.callPackage ./kanboard.nix {
ab8f306d 14 env = config.myEnv.tools.kanboard;
4288c2f2
IB
15 };
16 wallabag = pkgs.callPackage ./wallabag.nix {
17 inherit (pkgs.webapps) wallabag;
ab8f306d 18 env = config.myEnv.tools.wallabag;
4288c2f2
IB
19 };
20 yourls = pkgs.callPackage ./yourls.nix {
21 inherit (pkgs.webapps) yourls yourls-plugins;
ab8f306d 22 env = config.myEnv.tools.yourls;
4288c2f2
IB
23 };
24 rompr = pkgs.callPackage ./rompr.nix {
25 inherit (pkgs.webapps) rompr;
ab8f306d 26 env = config.myEnv.tools.rompr;
4288c2f2
IB
27 };
28 shaarli = pkgs.callPackage ./shaarli.nix {
ab8f306d 29 env = config.myEnv.tools.shaarli;
4288c2f2
IB
30 };
31 dokuwiki = pkgs.callPackage ./dokuwiki.nix {
32 inherit (pkgs.webapps) dokuwiki dokuwiki-plugins;
33 };
34 ldap = pkgs.callPackage ./ldap.nix {
35 inherit (pkgs.webapps) phpldapadmin;
ab8f306d 36 env = config.myEnv.tools.phpldapadmin;
4288c2f2 37 };
10889174 38
4288c2f2 39 cfg = config.myServices.websites.tools.tools;
10889174 40in {
4288c2f2 41 options.myServices.websites.tools.tools = {
10889174
IB
42 enable = lib.mkEnableOption "enable tools website";
43 };
44
45 config = lib.mkIf cfg.enable {
1a718805 46 secrets.keys =
a840a21c 47 kanboard.keys
8db8e666 48 ++ ldap.keys
8db8e666
IB
49 ++ shaarli.keys
50 ++ ttrss.keys
51 ++ wallabag.keys
52 ++ yourls.keys;
98163486 53
d2e703c5 54 services.duplyBackup.profiles = {
6a8252b1
IB
55 dokuwiki = dokuwiki.backups;
56 kanboard = kanboard.backups;
57 rompr = rompr.backups;
58 shaarli = shaarli.backups;
59 ttrss = ttrss.backups;
60 wallabag = wallabag.backups;
61 };
62
29f8cb85 63 services.websites.env.tools.modules =
1922655a
IB
64 [ "proxy_fcgi" ]
65 ++ adminer.apache.modules
10889174
IB
66 ++ ympd.apache.modules
67 ++ ttrss.apache.modules
133ebaee 68 ++ wallabag.apache.modules
bfe3c9c9 69 ++ yourls.apache.modules
95b20e17 70 ++ rompr.apache.modules
b892dcbe 71 ++ shaarli.apache.modules
f80772dc 72 ++ dokuwiki.apache.modules
d4ed0eff
IB
73 ++ ldap.apache.modules
74 ++ kanboard.apache.modules;
10889174 75
29f8cb85 76 services.websites.env.integration.vhostConfs.devtools = {
0f71cd76
IB
77 certName = "integration";
78 certMainHost = "devtools.immae.eu";
79 addToCerts = true;
80 hosts = [ "devtools.immae.eu" ];
81 root = "/var/lib/ftp/devtools.immae.eu";
82 extraConfig = [
0aae0181 83 ''
9338c832
IB
84 Timeout 600
85 ProxyTimeout 600
0aae0181
IB
86 <Directory "/var/lib/ftp/devtools.immae.eu">
87 DirectoryIndex index.php index.htm index.html
88 AllowOverride all
89 Require all granted
90 <FilesMatch "\.php$">
91 SetHandler "proxy:unix:/var/run/phpfpm/devtools.sock|fcgi://localhost"
92 </FilesMatch>
93 </Directory>
94 ''
46f30ecc
IB
95 ];
96 };
97
29f8cb85 98 services.websites.env.tools.vhostConfs.tools = {
10889174 99 certName = "eldiron";
7df420c2 100 addToCerts = true;
10889174 101 hosts = ["tools.immae.eu" ];
1922655a 102 root = "/var/lib/ftp/tools.immae.eu";
10889174 103 extraConfig = [
1922655a 104 ''
ea9c6fe8 105 RedirectMatch 301 ^/vpn(.*)$ https://vpn.immae.eu$1
afcc5de0 106 RedirectMatch 301 ^/roundcube(.*)$ https://mail.immae.eu/roundcube$1
3f453c7d 107 RedirectMatch 301 ^/jappix(.*)$ https://im.immae.fr/converse
afcc5de0 108
1922655a 109 <Directory "/var/lib/ftp/tools.immae.eu">
0eaac6ba 110 DirectoryIndex index.php index.htm index.html
1922655a
IB
111 AllowOverride all
112 Require all granted
113 <FilesMatch "\.php$">
114 SetHandler "proxy:unix:/var/run/phpfpm/tools.sock|fcgi://localhost"
115 </FilesMatch>
116 </Directory>
117 ''
10889174
IB
118 adminer.apache.vhostConf
119 ympd.apache.vhostConf
120 ttrss.apache.vhostConf
aebd817b 121 wallabag.apache.vhostConf
133ebaee 122 yourls.apache.vhostConf
bfe3c9c9 123 rompr.apache.vhostConf
95b20e17 124 shaarli.apache.vhostConf
b892dcbe 125 dokuwiki.apache.vhostConf
f80772dc 126 ldap.apache.vhostConf
d4ed0eff 127 kanboard.apache.vhostConf
10889174
IB
128 ];
129 };
130
29f8cb85 131 services.websites.env.tools.vhostConfs.outils = {
7df420c2
IB
132 certName = "eldiron";
133 addToCerts = true;
0f71cd76 134 hosts = [ "outils.immae.eu" ];
7df420c2 135 root = null;
70606070
IB
136 extraConfig = [
137 ''
138 RedirectMatch 301 ^/mediagoblin(.*)$ https://mgoblin.immae.eu$1
139
140 RedirectMatch 301 ^/ether(.*)$ https://ether.immae.eu$1
141
142 RedirectMatch 301 ^/nextcloud(.*)$ https://cloud.immae.eu$1
143 RedirectMatch 301 ^/owncloud(.*)$ https://cloud.immae.eu$1
144
145 RedirectMatch 301 ^/carddavmate(.*)$ https://dav.immae.eu/infcloud$1
146 RedirectMatch 301 ^/caldavzap(.*)$ https://dav.immae.eu/infcloud$1
147 RedirectMatch 301 ^/caldav.php(.*)$ https://dav.immae.eu/caldav.php$1
148 RedirectMatch 301 ^/davical(.*)$ https://dav.immae.eu/davical$1
149
150 RedirectMatch 301 ^/taskweb(.*)$ https://task.immae.eu/taskweb$1
151
afcc5de0
IB
152 RedirectMatch 301 ^/roundcube(.*)$ https://mail.immae.eu/roundcube$1
153
3f453c7d
IB
154 RedirectMatch 301 ^/jappix(.*)$ https://im.immae.fr/converse
155
ea9c6fe8
IB
156 RedirectMatch 301 ^/vpn(.*)$ https://vpn.immae.eu$1
157
70606070
IB
158 RedirectMatch 301 ^/(.*)$ https://tools.immae.eu/$1
159 ''
160 ];
161 };
162
f40f5b23
IB
163 systemd.services = {
164 phpfpm-dokuwiki = {
165 after = lib.mkAfter dokuwiki.phpFpm.serviceDeps;
166 wants = dokuwiki.phpFpm.serviceDeps;
167 };
168 phpfpm-kanboard = {
169 after = lib.mkAfter kanboard.phpFpm.serviceDeps;
170 wants = kanboard.phpFpm.serviceDeps;
171 };
172 phpfpm-ldap = {
173 after = lib.mkAfter ldap.phpFpm.serviceDeps;
174 wants = ldap.phpFpm.serviceDeps;
175 };
f40f5b23
IB
176 phpfpm-shaarli = {
177 after = lib.mkAfter shaarli.phpFpm.serviceDeps;
178 wants = shaarli.phpFpm.serviceDeps;
179 };
180 phpfpm-ttrss = {
181 after = lib.mkAfter ttrss.phpFpm.serviceDeps;
182 wants = ttrss.phpFpm.serviceDeps;
183 };
184 phpfpm-wallabag = {
185 after = lib.mkAfter wallabag.phpFpm.serviceDeps;
186 wants = wallabag.phpFpm.serviceDeps;
187 preStart = lib.mkAfter wallabag.phpFpm.preStart;
188 };
189 phpfpm-yourls = {
190 after = lib.mkAfter yourls.phpFpm.serviceDeps;
191 wants = yourls.phpFpm.serviceDeps;
192 };
193 ympd = {
194 description = "Standalone MPD Web GUI written in C";
195 wantedBy = [ "multi-user.target" ];
196 script = ''
197 export MPD_PASSWORD=$(cat /var/secrets/mpd)
198 ${pkgs.ympd}/bin/ympd --host ${ympd.config.host} --port ${toString ympd.config.port} --webport ${ympd.config.webPort} --user nobody
199 '';
200 };
201 tt-rss = {
202 description = "Tiny Tiny RSS feeds update daemon";
203 serviceConfig = {
204 User = "wwwrun";
205 ExecStart = "${pkgs.php}/bin/php ${ttrss.webRoot}/update.php --daemon";
206 StandardOutput = "syslog";
207 StandardError = "syslog";
208 PermissionsStartOnly = true;
209 };
210
211 wantedBy = [ "multi-user.target" ];
212 requires = ["postgresql.service"];
213 after = ["network.target" "postgresql.service"];
214 };
215 };
216
17f6eae9
IB
217 services.filesWatcher.ympd = {
218 restart = true;
219 paths = [ "/var/secrets/mpd" ];
220 };
221
f40f5b23
IB
222 services.phpfpm.pools.devtools = {
223 listen = "/var/run/phpfpm/devtools.sock";
224 extraConfig = ''
225 user = wwwrun
226 group = wwwrun
227 listen.owner = wwwrun
228 listen.group = wwwrun
229 pm = dynamic
230 pm.max_children = 60
231 pm.start_servers = 2
232 pm.min_spare_servers = 1
233 pm.max_spare_servers = 10
234
235 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/lib/ftp/devtools.immae.eu:/tmp"
236 '';
237 phpOptions = config.services.phpfpm.phpOptions + ''
c75b75a2 238 extension=${pkgs.php}/lib/php/extensions/mysqli.so
0aae0181
IB
239 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
240 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
241 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so
242 '';
8eded9ec 243 };
f40f5b23
IB
244
245 services.phpfpm.poolConfigs = {
10889174
IB
246 adminer = adminer.phpFpm.pool;
247 ttrss = ttrss.phpFpm.pool;
aebd817b 248 wallabag = wallabag.phpFpm.pool;
133ebaee 249 yourls = yourls.phpFpm.pool;
bfe3c9c9 250 rompr = rompr.phpFpm.pool;
95b20e17 251 shaarli = shaarli.phpFpm.pool;
b892dcbe 252 dokuwiki = dokuwiki.phpFpm.pool;
f80772dc 253 ldap = ldap.phpFpm.pool;
d4ed0eff 254 kanboard = kanboard.phpFpm.pool;
1922655a
IB
255 tools = ''
256 listen = /var/run/phpfpm/tools.sock
257 user = wwwrun
258 group = wwwrun
259 listen.owner = wwwrun
260 listen.group = wwwrun
261 pm = dynamic
262 pm.max_children = 60
263 pm.start_servers = 2
264 pm.min_spare_servers = 1
265 pm.max_spare_servers = 10
266
267 ; Needed to avoid clashes in browser cookies (same domain)
268 php_value[session.name] = ToolsPHPSESSID
269 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/lib/ftp/tools.immae.eu:/tmp"
270 '';
10889174
IB
271 };
272
273 system.activationScripts = {
4288c2f2 274 adminer = adminer.activationScript;
10889174 275 ttrss = ttrss.activationScript;
aebd817b 276 wallabag = wallabag.activationScript;
133ebaee 277 yourls = yourls.activationScript;
bfe3c9c9 278 rompr = rompr.activationScript;
95b20e17 279 shaarli = shaarli.activationScript;
b892dcbe 280 dokuwiki = dokuwiki.activationScript;
d4ed0eff 281 kanboard = kanboard.activationScript;
4288c2f2 282 ldap = ldap.activationScript;
10889174
IB
283 };
284
4288c2f2
IB
285 myServices.websites.webappDirs = {
286 _adminer = adminer.webRoot;
287 "${dokuwiki.apache.webappName}" = dokuwiki.webRoot;
288 "${ldap.apache.webappName}" = "${ldap.webRoot}/htdocs";
289 "${rompr.apache.webappName}" = rompr.webRoot;
4288c2f2
IB
290 "${shaarli.apache.webappName}" = shaarli.webRoot;
291 "${ttrss.apache.webappName}" = ttrss.webRoot;
292 "${wallabag.apache.webappName}" = wallabag.webRoot;
293 "${yourls.apache.webappName}" = yourls.webRoot;
4288c2f2
IB
294 "${kanboard.apache.webappName}" = kanboard.webRoot;
295 };
a95ab089 296
29f8cb85 297 services.websites.env.tools.watchPaths = [
9247b444 298 "/var/secrets/webapps/tools-shaarli"
17f6eae9
IB
299 ];
300 services.filesWatcher.phpfpm-wallabag = {
301 restart = true;
302 paths = [ "/var/secrets/webapps/tools-wallabag" ];
303 };
10889174
IB
304 };
305}
306