]>
Commit | Line | Data |
---|---|---|
f8bde3d6 | 1 | { lib, pkgs, config, mylibs, myconfig, ... }: |
42429ef0 IB |
2 | let |
3 | cfg = config.services.myWebsites; | |
f8bde3d6 IB |
4 | makeService = name: cfg: let |
5 | toVhost = vhostConf: { | |
6 | enableSSL = true; | |
7 | sslServerCert = "/var/lib/acme/${vhostConf.certName}/cert.pem"; | |
8 | sslServerKey = "/var/lib/acme/${vhostConf.certName}/key.pem"; | |
9 | sslServerChain = "/var/lib/acme/${vhostConf.certName}/fullchain.pem"; | |
10 | logFormat = "combinedVhost"; | |
11 | listen = [ | |
12 | { ip = cfg.ip; port = 443; } | |
13 | ]; | |
14 | hostName = builtins.head vhostConf.hosts; | |
15 | serverAliases = builtins.tail vhostConf.hosts or []; | |
16 | documentRoot = vhostConf.root; | |
17 | extraConfig = builtins.concatStringsSep "\n" vhostConf.extraConfig; | |
18 | }; | |
950ca5ee IB |
19 | redirectVhost = { # Should go last, catchall http -> https redirect |
20 | listen = [ { ip = cfg.ip; port = 80; } ]; | |
21 | hostName = "redirectSSL"; | |
22 | serverAliases = [ "*" ]; | |
23 | enableSSL = false; | |
24 | logFormat = "combinedVhost"; | |
25 | documentRoot = "/var/lib/acme/acme-challenge"; | |
26 | extraConfig = '' | |
27 | RewriteEngine on | |
28 | RewriteCond "%{REQUEST_URI}" "!^/\.well-known" | |
29 | RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301] | |
30 | # To redirect in specific "VirtualHost *:80", do | |
31 | # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1 | |
32 | # rather than rewrite | |
33 | ''; | |
34 | }; | |
35 | fallbackVhost = toVhost { # Should go first, default choice | |
36 | certName = "eldiron"; | |
37 | hosts = ["eldiron.immae.eu" ]; | |
38 | root = ../../www; | |
39 | extraConfig = [ "DirectoryIndex index.htm" ]; | |
40 | }; | |
f8bde3d6 IB |
41 | in rec { |
42 | enable = true; | |
43 | listen = [ | |
44 | { ip = cfg.ip; port = 443; } | |
45 | ]; | |
46 | stateDir = "/run/httpd_${name}"; | |
47 | logPerVirtualHost = true; | |
48 | multiProcessingModule = "worker"; | |
49 | adminAddr = "httpd@immae.eu"; | |
50 | logFormat = "combinedVhost"; | |
51 | extraModules = pkgs.lib.lists.unique (pkgs.lib.lists.flatten cfg.modules); | |
52 | extraConfig = builtins.concatStringsSep "\n" cfg.extraConfig; | |
950ca5ee IB |
53 | virtualHosts = [ fallbackVhost ] |
54 | ++ (pkgs.lib.attrsets.mapAttrsToList (n: v: toVhost v) cfg.vhostConfs) | |
55 | ++ [ redirectVhost ]; | |
f8bde3d6 IB |
56 | }; |
57 | makeServiceOptions = name: ip: { | |
58 | enable = lib.mkEnableOption "enable websites in ${name}"; | |
59 | ip = lib.mkOption { | |
60 | type = lib.types.string; | |
61 | default = ip; | |
62 | description = "${name} ip to listen to"; | |
63 | }; | |
64 | modules = lib.mkOption { | |
65 | type = lib.types.listOf (lib.types.str); | |
66 | default = []; | |
67 | }; | |
68 | extraConfig = lib.mkOption { | |
69 | type = lib.types.listOf (lib.types.lines); | |
70 | default = []; | |
71 | }; | |
72 | vhostConfs = lib.mkOption { | |
73 | type = lib.types.attrsOf (lib.types.submodule { | |
74 | options = { | |
75 | certName = lib.mkOption { type = lib.types.string; }; | |
76 | hosts = lib.mkOption { type = lib.types.listOf lib.types.string; }; | |
77 | root = lib.mkOption { type = lib.types.nullOr lib.types.path; }; | |
78 | extraConfig = lib.mkOption { type = lib.types.listOf lib.types.lines; default = []; }; | |
79 | }; | |
80 | }); | |
81 | }; | |
82 | }; | |
f8d3b61a IB |
83 | makeModules = cfg: pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig); |
84 | makeExtraConfig = cfg: (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig)); | |
42429ef0 IB |
85 | in |
86 | { | |
87 | imports = [ | |
54307da4 IB |
88 | ./chloe |
89 | ./ludivine | |
90 | ./aten | |
91 | ./piedsjaloux | |
92 | ./connexionswing | |
2f0f1c48 | 93 | ./tellesflorian |
d578d270 | 94 | ./ftp/jerome.nix |
53b8fad9 | 95 | ./ftp/nassime.nix |
79f239be | 96 | ./ftp/florian.nix |
10889174 IB |
97 | ./tools/db |
98 | ./tools/tools | |
99 | ./tools/dav | |
100 | ./tools/cloud | |
101 | ./tools/git | |
35a397cd | 102 | ./tools/mastodon |
56eba416 | 103 | ./tools/mediagoblin |
a7f7fdae | 104 | ./tools/diaspora |
17146204 | 105 | ./tools/ether |
f8bde3d6 IB |
106 | # built using: |
107 | # sed -e "s/services\.httpd/services\.httpdProd/g" .nix-defexpr/channels/nixpkgs/nixos/modules/services/web-servers/apache-httpd/default.nix | |
273e2c61 | 108 | # Removed allGranted |
f8bde3d6 | 109 | # And removed users / groups |
54307da4 IB |
110 | ./apache/httpd_prod.nix |
111 | ./apache/httpd_inte.nix | |
273e2c61 IB |
112 | # except for this one for users/groups |
113 | ./apache/httpd_tools.nix | |
10889174 IB |
114 | # Adapted from base phpfpm |
115 | ./phpfpm | |
42429ef0 IB |
116 | ]; |
117 | ||
118 | options.services.myWebsites = { | |
f8bde3d6 IB |
119 | production = makeServiceOptions "production" myconfig.ips.production; |
120 | integration = makeServiceOptions "integration" myconfig.ips.integration; | |
950ca5ee | 121 | tools = makeServiceOptions "tools" myconfig.ips.main; |
42429ef0 IB |
122 | |
123 | apacheConfig = lib.mkOption { | |
124 | type = lib.types.attrsOf (lib.types.submodule { | |
125 | options = { | |
126 | modules = lib.mkOption { | |
127 | type = lib.types.listOf (lib.types.str); | |
128 | default = []; | |
129 | }; | |
130 | extraConfig = lib.mkOption { | |
131 | type = lib.types.nullOr lib.types.lines; | |
132 | default = null; | |
133 | }; | |
134 | }; | |
135 | }); | |
136 | default = {}; | |
137 | description = "Extra global config"; | |
138 | }; | |
139 | ||
140 | }; | |
141 | ||
142 | config = { | |
54307da4 IB |
143 | networking = { |
144 | firewall = { | |
145 | enable = true; | |
146 | allowedTCPPorts = [ 80 443 ]; | |
147 | }; | |
148 | interfaces."eth0".ipv4.addresses = [ | |
149 | # 176.9.151.89 declared in nixops -> infra / tools | |
150 | { address = myconfig.ips.production; prefixLength = 32; } | |
151 | { address = myconfig.ips.integration; prefixLength = 32; } | |
152 | ]; | |
153 | }; | |
154 | ||
98584540 IB |
155 | nixpkgs.config.packageOverrides = oldpkgs: rec { |
156 | php = php72; | |
157 | php72 = (oldpkgs.php72.override { | |
158 | mysql.connector-c = pkgs.mariadb; | |
159 | config.php.mysqlnd = false; | |
160 | config.php.mysqli = false; | |
161 | }).overrideAttrs(old: rec { | |
162 | # Didn't manage to build with mysqli + mysql_config connector | |
163 | configureFlags = old.configureFlags ++ [ | |
912921a7 | 164 | "--with-mysqli=shared,mysqlnd" |
98584540 IB |
165 | ]; |
166 | # preConfigure = (old.preConfigure or "") + '' | |
167 | # export CPPFLAGS="$CPPFLAGS -I${pkgs.mariadb}/include/mysql/server"; | |
168 | # sed -i -e 's/#include "mysqli_priv.h"/#include "mysqli_priv.h"\n#include <mysql_version.h>/' \ | |
169 | # ext/mysqli/mysqli.c ext/mysqli/mysqli_prop.c | |
170 | # ''; | |
171 | }); | |
172 | phpPackages = oldpkgs.php72Packages.override { inherit php; }; | |
d78128ec IB |
173 | composerEnv = import ./commons/composer-env.nix { |
174 | inherit (pkgs) stdenv writeTextFile fetchurl php unzip; | |
175 | }; | |
98584540 IB |
176 | }; |
177 | ||
10889174 IB |
178 | services.myWebsites.tools.databases.enable = true; |
179 | services.myWebsites.tools.tools.enable = true; | |
180 | services.myWebsites.tools.dav.enable = true; | |
181 | services.myWebsites.tools.cloud.enable = true; | |
182 | services.myWebsites.tools.git.enable = true; | |
35a397cd | 183 | services.myWebsites.tools.mastodon.enable = true; |
56eba416 | 184 | services.myWebsites.tools.mediagoblin.enable = true; |
a7f7fdae | 185 | services.myWebsites.tools.diaspora.enable = true; |
17146204 | 186 | services.myWebsites.tools.etherpad-lite.enable = true; |
10889174 | 187 | |
42429ef0 IB |
188 | services.myWebsites.Chloe.production.enable = cfg.production.enable; |
189 | services.myWebsites.Ludivine.production.enable = cfg.production.enable; | |
190 | services.myWebsites.Aten.production.enable = cfg.production.enable; | |
191 | services.myWebsites.PiedsJaloux.production.enable = cfg.production.enable; | |
192 | services.myWebsites.Connexionswing.production.enable = cfg.production.enable; | |
d578d270 | 193 | services.myWebsites.Jerome.production.enable = cfg.production.enable; |
53b8fad9 | 194 | services.myWebsites.Nassime.production.enable = cfg.production.enable; |
79f239be | 195 | services.myWebsites.Florian.production.enable = cfg.production.enable; |
42429ef0 IB |
196 | |
197 | services.myWebsites.Chloe.integration.enable = cfg.integration.enable; | |
198 | services.myWebsites.Ludivine.integration.enable = cfg.integration.enable; | |
199 | services.myWebsites.Aten.integration.enable = cfg.integration.enable; | |
200 | services.myWebsites.PiedsJaloux.integration.enable = cfg.integration.enable; | |
201 | services.myWebsites.Connexionswing.integration.enable = cfg.integration.enable; | |
2f0f1c48 | 202 | services.myWebsites.TellesFlorian.integration.enable = true; |
79f239be | 203 | services.myWebsites.Florian.integration.enable = true; |
42429ef0 IB |
204 | |
205 | services.myWebsites.apacheConfig = { | |
206 | gzip = { | |
207 | modules = [ "deflate" "filter" ]; | |
208 | extraConfig = '' | |
209 | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript | |
210 | ''; | |
211 | }; | |
212 | macros = { | |
213 | modules = [ "macro" ]; | |
214 | }; | |
215 | ldap = { | |
216 | modules = [ "ldap" "authnz_ldap" ]; | |
9d90e7e2 | 217 | extraConfig = '' |
42429ef0 IB |
218 | <IfModule ldap_module> |
219 | LDAPSharedCacheSize 500000 | |
220 | LDAPCacheEntries 1024 | |
221 | LDAPCacheTTL 600 | |
222 | LDAPOpCacheEntries 1024 | |
223 | LDAPOpCacheTTL 600 | |
224 | </IfModule> | |
225 | ||
226 | <Macro LDAPConnect> | |
227 | <IfModule authnz_ldap_module> | |
228 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS | |
229 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | |
9d90e7e2 | 230 | AuthLDAPBindPassword "${myconfig.env.httpd.ldap.password}" |
42429ef0 IB |
231 | AuthType Basic |
232 | AuthName "Authentification requise (Acces LDAP)" | |
233 | AuthBasicProvider ldap | |
234 | </IfModule> | |
235 | </Macro> | |
236 | ||
237 | <Macro Stats %{domain}> | |
238 | Alias /awstats /var/lib/goaccess/%{domain} | |
239 | <Directory /var/lib/goaccess/%{domain}> | |
240 | DirectoryIndex index.html | |
241 | AllowOverride None | |
242 | Require all granted | |
243 | </Directory> | |
244 | <Location /awstats> | |
245 | Use LDAPConnect | |
246 | Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu | |
247 | </Location> | |
248 | </Macro> | |
646bdf3e IB |
249 | |
250 | ErrorDocument 500 /maintenance_immae.html | |
251 | ErrorDocument 501 /maintenance_immae.html | |
252 | ErrorDocument 502 /maintenance_immae.html | |
253 | ErrorDocument 503 /maintenance_immae.html | |
254 | ErrorDocument 504 /maintenance_immae.html | |
255 | Alias /maintenance_immae.html ${../../www}/maintenance_immae.html | |
256 | ProxyPass /maintenance_immae.html ! | |
257 | ||
258 | AliasMatch "(.*)/googleb6d69446ff4ca3e5.html" ${../../www}/googleb6d69446ff4ca3e5.html | |
42429ef0 IB |
259 | ''; |
260 | }; | |
261 | http2 = { | |
262 | modules = [ "http2" ]; | |
263 | extraConfig = '' | |
264 | Protocols h2 http/1.1 | |
265 | ''; | |
266 | }; | |
267 | customLog = { | |
268 | extraConfig = '' | |
269 | LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost | |
270 | ''; | |
271 | }; | |
272 | }; | |
f8bde3d6 | 273 | |
10889174 IB |
274 | system.activationScripts = { |
275 | httpd = '' | |
276 | install -d -m 0755 /var/lib/acme/acme-challenge | |
277 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions | |
278 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/adminer | |
279 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt | |
280 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/davical | |
281 | ''; | |
282 | }; | |
283 | ||
284 | services.myPhpfpm = { | |
285 | phpPackage = pkgs.php; | |
286 | phpOptions = '' | |
287 | session.save_path = "/var/lib/php/sessions" | |
288 | session.gc_maxlifetime = 60*60*24*15 | |
289 | session.cache_expire = 60*24*30 | |
290 | ''; | |
291 | extraConfig = '' | |
292 | log_level = notice | |
293 | ''; | |
294 | }; | |
295 | ||
f8bde3d6 | 296 | services.httpdProd = makeService "production" config.services.myWebsites.production; |
f8d3b61a IB |
297 | services.myWebsites.production.modules = makeModules cfg; |
298 | services.myWebsites.production.extraConfig = makeExtraConfig cfg; | |
f8bde3d6 IB |
299 | |
300 | services.httpdInte = makeService "integration" config.services.myWebsites.integration; | |
f8d3b61a IB |
301 | services.myWebsites.integration.modules = makeModules cfg; |
302 | services.myWebsites.integration.extraConfig = makeExtraConfig cfg; | |
950ca5ee | 303 | |
273e2c61 | 304 | services.httpdTools = makeService "tools" config.services.myWebsites.tools; |
f8d3b61a IB |
305 | services.myWebsites.tools.modules = makeModules cfg; |
306 | services.myWebsites.tools.extraConfig = makeExtraConfig cfg ++ | |
646bdf3e IB |
307 | [ '' |
308 | RedirectMatch ^/licen[cs]es?_et_tip(ping)?$ https://www.immae.eu/licences_et_tip.html | |
309 | RedirectMatch ^/licen[cs]es?_and_tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html | |
310 | RedirectMatch ^/licen[cs]es?$ https://www.immae.eu/licenses_and_tipping.html | |
311 | RedirectMatch ^/tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html | |
312 | RedirectMatch ^/(mentions|mentions_legales|legal)$ https://www.immae.eu/mentions.html | |
313 | RedirectMatch ^/CGU$ https://www.immae.eu/CGU | |
314 | '' | |
315 | ] | |
316 | ; | |
42429ef0 IB |
317 | }; |
318 | } |