]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/default.nix
Add backup module
[perso/Immae/Config/Nix.git] / modules / private / websites / default.nix
1 { lib, pkgs, config, myconfig, ... }:
2 let
3 www_root = "/run/current-system/webapps/_www";
4 theme_root = "/run/current-system/webapps/_theme";
5 apacheConfig = {
6 gzip = {
7 modules = [ "deflate" "filter" ];
8 extraConfig = ''
9 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
10 '';
11 };
12 macros = {
13 modules = [ "macro" ];
14 };
15 stats = {
16 extraConfig = ''
17 <Macro Stats %{domain}>
18 Alias /webstats ${config.services.webstats.dataDir}/%{domain}
19 <Directory ${config.services.webstats.dataDir}/%{domain}>
20 DirectoryIndex index.html
21 AllowOverride None
22 Require all granted
23 </Directory>
24 <Location /webstats>
25 Use LDAPConnect
26 Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
27 </Location>
28 </Macro>
29 '';
30 };
31 ldap = {
32 modules = [ "ldap" "authnz_ldap" ];
33 extraConfig = ''
34 <IfModule ldap_module>
35 LDAPSharedCacheSize 500000
36 LDAPCacheEntries 1024
37 LDAPCacheTTL 600
38 LDAPOpCacheEntries 1024
39 LDAPOpCacheTTL 600
40 </IfModule>
41
42 Include /var/secrets/apache-ldap
43 '';
44 };
45 global = {
46 extraConfig = (pkgs.webapps.apache-default.override { inherit www_root;}).apacheConfig;
47 };
48 apaxy = {
49 extraConfig = (pkgs.webapps.apache-theme.override { inherit theme_root; }).apacheConfig;
50 };
51 http2 = {
52 modules = [ "http2" ];
53 extraConfig = ''
54 Protocols h2 http/1.1
55 '';
56 };
57 customLog = {
58 extraConfig = ''
59 LogFormat "%{Host}i:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost
60 '';
61 };
62 };
63 makeModules = lib.lists.flatten (lib.attrsets.mapAttrsToList (n: v: v.modules or []) apacheConfig);
64 makeExtraConfig = (builtins.filter (x: x != null) (lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) apacheConfig));
65 in
66 {
67 options.myServices.websites.webappDirs = lib.mkOption {
68 type = lib.types.attrsOf lib.types.path;
69 description = ''
70 Webapp paths to create in /run/current-system/webapps
71 '';
72 default = {};
73 };
74
75 config = {
76 services.backup.profiles.php = {
77 rootDir = "/var/lib/php";
78 };
79 users.users.wwwrun.extraGroups = [ "keys" ];
80 networking.firewall.allowedTCPPorts = [ 80 443 ];
81
82 nixpkgs.overlays = [ (self: super: rec {
83 #openssl = self.openssl_1_1;
84 php = php72;
85 php72 = (super.php72.override {
86 mysql.connector-c = self.mariadb;
87 config.php.mysqlnd = false;
88 config.php.mysqli = false;
89 }).overrideAttrs(old: rec {
90 # Didn't manage to build with mysqli + mysql_config connector
91 configureFlags = old.configureFlags ++ [
92 "--with-mysqli=shared,mysqlnd"
93 ];
94 # preConfigure = (old.preConfigure or "") + ''
95 # export CPPFLAGS="$CPPFLAGS -I${pkgs.mariadb}/include/mysql/server";
96 # sed -i -e 's/#include "mysqli_priv.h"/#include "mysqli_priv.h"\n#include <mysql_version.h>/' \
97 # ext/mysqli/mysqli.c ext/mysqli/mysqli_prop.c
98 # '';
99 });
100 phpPackages = super.php72Packages.override { inherit php; };
101 }) ];
102
103 secrets.keys = [{
104 dest = "apache-ldap";
105 user = "wwwrun";
106 group = "wwwrun";
107 permissions = "0400";
108 text = ''
109 <Macro LDAPConnect>
110 <IfModule authnz_ldap_module>
111 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS
112 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
113 AuthLDAPBindPassword "${myconfig.env.httpd.ldap.password}"
114 AuthType Basic
115 AuthName "Authentification requise (Acces LDAP)"
116 AuthBasicProvider ldap
117 </IfModule>
118 </Macro>
119 '';
120 }];
121
122 system.activationScripts = {
123 httpd = ''
124 install -d -m 0755 ${config.security.acme.directory}/acme-challenge
125 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions
126 '';
127 };
128
129 services.phpfpm = {
130 phpPackage = pkgs.php;
131 phpOptions = ''
132 session.save_path = "/var/lib/php/sessions"
133 post_max_size = 20M
134 ; 15 days (seconds)
135 session.gc_maxlifetime = 1296000
136 ; 30 days (minutes)
137 session.cache_expire = 43200
138 '';
139 extraConfig = ''
140 log_level = notice
141 '';
142 };
143
144 services.filesWatcher.httpdProd.paths = [ "/var/secrets/apache-ldap" ];
145 services.filesWatcher.httpdInte.paths = [ "/var/secrets/apache-ldap" ];
146 services.filesWatcher.httpdTools.paths = [ "/var/secrets/apache-ldap" ];
147
148 services.websites.env.production = {
149 enable = true;
150 adminAddr = "httpd@immae.eu";
151 httpdName = "Prod";
152 ips =
153 let ips = myconfig.env.servers.eldiron.ips.production;
154 in [ips.ip4] ++ (ips.ip6 or []);
155 modules = makeModules;
156 extraConfig = makeExtraConfig;
157 fallbackVhost = {
158 certName = "eldiron";
159 hosts = ["eldiron.immae.eu" ];
160 root = www_root;
161 extraConfig = [ "DirectoryIndex index.htm" ];
162 };
163 };
164
165 services.websites.env.integration = {
166 enable = true;
167 adminAddr = "httpd@immae.eu";
168 httpdName = "Inte";
169 ips =
170 let ips = myconfig.env.servers.eldiron.ips.integration;
171 in [ips.ip4] ++ (ips.ip6 or []);
172 modules = makeModules;
173 extraConfig = makeExtraConfig;
174 fallbackVhost = {
175 certName = "eldiron";
176 hosts = ["eldiron.immae.eu" ];
177 root = www_root;
178 extraConfig = [ "DirectoryIndex index.htm" ];
179 };
180 };
181
182 services.websites.env.tools = {
183 enable = true;
184 adminAddr = "httpd@immae.eu";
185 httpdName = "Tools";
186 ips =
187 let ips = myconfig.env.servers.eldiron.ips.main;
188 in [ips.ip4] ++ (ips.ip6 or []);
189 modules = makeModules;
190 extraConfig = makeExtraConfig ++
191 [ ''
192 RedirectMatch ^/licen[cs]es?_et_tip(ping)?$ https://www.immae.eu/licences_et_tip.html
193 RedirectMatch ^/licen[cs]es?_and_tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html
194 RedirectMatch ^/licen[cs]es?$ https://www.immae.eu/licenses_and_tipping.html
195 RedirectMatch ^/tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html
196 RedirectMatch ^/(mentions|mentions_legales|legal)$ https://www.immae.eu/mentions.html
197 RedirectMatch ^/CGU$ https://www.immae.eu/CGU
198 ''
199 ];
200 nosslVhost = {
201 enable = true;
202 host = "nossl.immae.eu";
203 };
204 fallbackVhost = {
205 certName = "eldiron";
206 hosts = ["eldiron.immae.eu" ];
207 root = www_root;
208 extraConfig = [ "DirectoryIndex index.htm" ];
209 };
210 };
211
212 system.extraSystemBuilderCmds = lib.mkIf (builtins.length (builtins.attrValues config.myServices.websites.webappDirs) > 0) ''
213 mkdir -p $out/webapps
214 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (name: path: "ln -s ${path} $out/webapps/${name}") config.myServices.websites.webappDirs)}
215 '';
216
217 myServices.websites = {
218 webappDirs = {
219 _www = pkgs.webapps.apache-default.www;
220 _theme = pkgs.webapps.apache-theme.theme;
221 };
222
223 aten.integration.enable = true;
224 aten.production.enable = true;
225
226 capitaines.production.enable = true;
227
228 chloe.integration.enable = true;
229 chloe.production.enable = true;
230
231 connexionswing.integration.enable = true;
232 connexionswing.production.enable = true;
233
234 denisejerome.production.enable = true;
235
236 emilia.production.enable = true;
237
238 florian.app.enable = true;
239 florian.integration.enable = true;
240 florian.production.enable = true;
241
242 immae.production.enable = true;
243 immae.release.enable = true;
244 immae.temp.enable = true;
245
246 leila.production.enable = true;
247
248 ludivinecassal.integration.enable = true;
249 ludivinecassal.production.enable = true;
250
251 nassime.production.enable = true;
252
253 naturaloutil.production.enable = true;
254 telioTortay.production.enable = true;
255
256 papa.surveillance.enable = true;
257
258 piedsjaloux.integration.enable = true;
259 piedsjaloux.production.enable = true;
260
261 tools.cloud.enable = true;
262 tools.dav.enable = true;
263 tools.db.enable = true;
264 tools.diaspora.enable = true;
265 tools.etherpad-lite.enable = true;
266 tools.git.enable = true;
267 tools.mastodon.enable = true;
268 tools.mediagoblin.enable = true;
269 tools.peertube.enable = true;
270 tools.tools.enable = true;
271 tools.email.enable = true;
272 };
273 };
274 }