diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 23:15:08 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 23:15:08 +0100 |
commit | 01f21083a897b86bf148f1d2bb9c8edca4d3786a (patch) | |
tree | 784f04e9b6ef99a49e572c84e4b7ab40b5eb5fde /virtual/modules/websites/default.nix | |
parent | bfe3c9c9df0c5112bc8806483292b55ed0f7e02d (diff) | |
download | Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.gz Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.zst Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.zip |
Rename virtual folder to nixops
Fixes https://git.immae.eu/mantisbt/view.php?id=82
Diffstat (limited to 'virtual/modules/websites/default.nix')
-rw-r--r-- | virtual/modules/websites/default.nix | 311 |
1 files changed, 0 insertions, 311 deletions
diff --git a/virtual/modules/websites/default.nix b/virtual/modules/websites/default.nix deleted file mode 100644 index 4d5ae23..0000000 --- a/virtual/modules/websites/default.nix +++ /dev/null | |||
@@ -1,311 +0,0 @@ | |||
1 | { lib, pkgs, config, mylibs, myconfig, ... }: | ||
2 | let | ||
3 | cfg = config.services.myWebsites; | ||
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 | }; | ||
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 | }; | ||
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; | ||
53 | virtualHosts = [ fallbackVhost ] | ||
54 | ++ (pkgs.lib.attrsets.mapAttrsToList (n: v: toVhost v) cfg.vhostConfs) | ||
55 | ++ [ redirectVhost ]; | ||
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 | }; | ||
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)); | ||
85 | in | ||
86 | { | ||
87 | imports = [ | ||
88 | ./chloe | ||
89 | ./ludivine | ||
90 | ./aten | ||
91 | ./piedsjaloux | ||
92 | ./connexionswing | ||
93 | ./tellesflorian | ||
94 | ./tools/db | ||
95 | ./tools/tools | ||
96 | ./tools/dav | ||
97 | ./tools/cloud | ||
98 | ./tools/git | ||
99 | ./tools/mastodon | ||
100 | ./tools/mediagoblin | ||
101 | ./tools/diaspora | ||
102 | ./tools/ether | ||
103 | # built using: | ||
104 | # sed -e "s/services\.httpd/services\.httpdProd/g" .nix-defexpr/channels/nixpkgs/nixos/modules/services/web-servers/apache-httpd/default.nix | ||
105 | # Removed allGranted | ||
106 | # And removed users / groups | ||
107 | ./apache/httpd_prod.nix | ||
108 | ./apache/httpd_inte.nix | ||
109 | # except for this one for users/groups | ||
110 | ./apache/httpd_tools.nix | ||
111 | # Adapted from base phpfpm | ||
112 | ./phpfpm | ||
113 | ]; | ||
114 | |||
115 | options.services.myWebsites = { | ||
116 | production = makeServiceOptions "production" myconfig.ips.production; | ||
117 | integration = makeServiceOptions "integration" myconfig.ips.integration; | ||
118 | tools = makeServiceOptions "tools" myconfig.ips.main; | ||
119 | |||
120 | apacheConfig = lib.mkOption { | ||
121 | type = lib.types.attrsOf (lib.types.submodule { | ||
122 | options = { | ||
123 | modules = lib.mkOption { | ||
124 | type = lib.types.listOf (lib.types.str); | ||
125 | default = []; | ||
126 | }; | ||
127 | extraConfig = lib.mkOption { | ||
128 | type = lib.types.nullOr lib.types.lines; | ||
129 | default = null; | ||
130 | }; | ||
131 | }; | ||
132 | }); | ||
133 | default = {}; | ||
134 | description = "Extra global config"; | ||
135 | }; | ||
136 | |||
137 | }; | ||
138 | |||
139 | config = { | ||
140 | networking = { | ||
141 | firewall = { | ||
142 | enable = true; | ||
143 | allowedTCPPorts = [ 80 443 ]; | ||
144 | }; | ||
145 | interfaces."eth0".ipv4.addresses = [ | ||
146 | # 176.9.151.89 declared in nixops -> infra / tools | ||
147 | { address = myconfig.ips.production; prefixLength = 32; } | ||
148 | { address = myconfig.ips.integration; prefixLength = 32; } | ||
149 | ]; | ||
150 | }; | ||
151 | |||
152 | nixpkgs.config.packageOverrides = oldpkgs: rec { | ||
153 | php = php72; | ||
154 | php72 = (oldpkgs.php72.override { | ||
155 | mysql.connector-c = pkgs.mariadb; | ||
156 | config.php.mysqlnd = false; | ||
157 | config.php.mysqli = false; | ||
158 | }).overrideAttrs(old: rec { | ||
159 | # Didn't manage to build with mysqli + mysql_config connector | ||
160 | configureFlags = old.configureFlags ++ [ | ||
161 | "--with-mysqli=shared,mysqlnd" | ||
162 | ]; | ||
163 | # preConfigure = (old.preConfigure or "") + '' | ||
164 | # export CPPFLAGS="$CPPFLAGS -I${pkgs.mariadb}/include/mysql/server"; | ||
165 | # sed -i -e 's/#include "mysqli_priv.h"/#include "mysqli_priv.h"\n#include <mysql_version.h>/' \ | ||
166 | # ext/mysqli/mysqli.c ext/mysqli/mysqli_prop.c | ||
167 | # ''; | ||
168 | }); | ||
169 | phpPackages = oldpkgs.php72Packages.override { inherit php; }; | ||
170 | composerEnv = import ./commons/composer-env.nix { | ||
171 | inherit (pkgs) stdenv writeTextFile fetchurl php unzip; | ||
172 | }; | ||
173 | }; | ||
174 | |||
175 | services.myWebsites.tools.databases.enable = true; | ||
176 | services.myWebsites.tools.tools.enable = true; | ||
177 | services.myWebsites.tools.dav.enable = true; | ||
178 | services.myWebsites.tools.cloud.enable = true; | ||
179 | services.myWebsites.tools.git.enable = true; | ||
180 | services.myWebsites.tools.mastodon.enable = true; | ||
181 | services.myWebsites.tools.mediagoblin.enable = true; | ||
182 | services.myWebsites.tools.diaspora.enable = true; | ||
183 | services.myWebsites.tools.etherpad-lite.enable = true; | ||
184 | |||
185 | services.myWebsites.Chloe.production.enable = cfg.production.enable; | ||
186 | services.myWebsites.Ludivine.production.enable = cfg.production.enable; | ||
187 | services.myWebsites.Aten.production.enable = cfg.production.enable; | ||
188 | services.myWebsites.PiedsJaloux.production.enable = cfg.production.enable; | ||
189 | services.myWebsites.Connexionswing.production.enable = cfg.production.enable; | ||
190 | |||
191 | services.myWebsites.Chloe.integration.enable = cfg.integration.enable; | ||
192 | services.myWebsites.Ludivine.integration.enable = cfg.integration.enable; | ||
193 | services.myWebsites.Aten.integration.enable = cfg.integration.enable; | ||
194 | services.myWebsites.PiedsJaloux.integration.enable = cfg.integration.enable; | ||
195 | services.myWebsites.Connexionswing.integration.enable = cfg.integration.enable; | ||
196 | services.myWebsites.TellesFlorian.integration.enable = true; | ||
197 | |||
198 | services.myWebsites.apacheConfig = { | ||
199 | gzip = { | ||
200 | modules = [ "deflate" "filter" ]; | ||
201 | extraConfig = '' | ||
202 | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript | ||
203 | ''; | ||
204 | }; | ||
205 | macros = { | ||
206 | modules = [ "macro" ]; | ||
207 | }; | ||
208 | ldap = { | ||
209 | modules = [ "ldap" "authnz_ldap" ]; | ||
210 | extraConfig = '' | ||
211 | <IfModule ldap_module> | ||
212 | LDAPSharedCacheSize 500000 | ||
213 | LDAPCacheEntries 1024 | ||
214 | LDAPCacheTTL 600 | ||
215 | LDAPOpCacheEntries 1024 | ||
216 | LDAPOpCacheTTL 600 | ||
217 | </IfModule> | ||
218 | |||
219 | <Macro LDAPConnect> | ||
220 | <IfModule authnz_ldap_module> | ||
221 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS | ||
222 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | ||
223 | AuthLDAPBindPassword "${myconfig.env.httpd.ldap.password}" | ||
224 | AuthType Basic | ||
225 | AuthName "Authentification requise (Acces LDAP)" | ||
226 | AuthBasicProvider ldap | ||
227 | </IfModule> | ||
228 | </Macro> | ||
229 | |||
230 | <Macro Stats %{domain}> | ||
231 | Alias /awstats /var/lib/goaccess/%{domain} | ||
232 | <Directory /var/lib/goaccess/%{domain}> | ||
233 | DirectoryIndex index.html | ||
234 | AllowOverride None | ||
235 | Require all granted | ||
236 | </Directory> | ||
237 | <Location /awstats> | ||
238 | Use LDAPConnect | ||
239 | Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu | ||
240 | </Location> | ||
241 | </Macro> | ||
242 | |||
243 | ErrorDocument 500 /maintenance_immae.html | ||
244 | ErrorDocument 501 /maintenance_immae.html | ||
245 | ErrorDocument 502 /maintenance_immae.html | ||
246 | ErrorDocument 503 /maintenance_immae.html | ||
247 | ErrorDocument 504 /maintenance_immae.html | ||
248 | Alias /maintenance_immae.html ${../../www}/maintenance_immae.html | ||
249 | ProxyPass /maintenance_immae.html ! | ||
250 | |||
251 | AliasMatch "(.*)/googleb6d69446ff4ca3e5.html" ${../../www}/googleb6d69446ff4ca3e5.html | ||
252 | ''; | ||
253 | }; | ||
254 | http2 = { | ||
255 | modules = [ "http2" ]; | ||
256 | extraConfig = '' | ||
257 | Protocols h2 http/1.1 | ||
258 | ''; | ||
259 | }; | ||
260 | customLog = { | ||
261 | extraConfig = '' | ||
262 | LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost | ||
263 | ''; | ||
264 | }; | ||
265 | }; | ||
266 | |||
267 | system.activationScripts = { | ||
268 | httpd = '' | ||
269 | install -d -m 0755 /var/lib/acme/acme-challenge | ||
270 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions | ||
271 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/adminer | ||
272 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt | ||
273 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/davical | ||
274 | ''; | ||
275 | }; | ||
276 | |||
277 | services.myPhpfpm = { | ||
278 | phpPackage = pkgs.php; | ||
279 | phpOptions = '' | ||
280 | session.save_path = "/var/lib/php/sessions" | ||
281 | session.gc_maxlifetime = 60*60*24*15 | ||
282 | session.cache_expire = 60*24*30 | ||
283 | ''; | ||
284 | extraConfig = '' | ||
285 | log_level = notice | ||
286 | ''; | ||
287 | }; | ||
288 | |||
289 | services.httpdProd = makeService "production" config.services.myWebsites.production; | ||
290 | services.myWebsites.production.modules = makeModules cfg; | ||
291 | services.myWebsites.production.extraConfig = makeExtraConfig cfg; | ||
292 | |||
293 | services.httpdInte = makeService "integration" config.services.myWebsites.integration; | ||
294 | services.myWebsites.integration.modules = makeModules cfg; | ||
295 | services.myWebsites.integration.extraConfig = makeExtraConfig cfg; | ||
296 | |||
297 | services.httpdTools = makeService "tools" config.services.myWebsites.tools; | ||
298 | services.myWebsites.tools.modules = makeModules cfg; | ||
299 | services.myWebsites.tools.extraConfig = makeExtraConfig cfg ++ | ||
300 | [ '' | ||
301 | RedirectMatch ^/licen[cs]es?_et_tip(ping)?$ https://www.immae.eu/licences_et_tip.html | ||
302 | RedirectMatch ^/licen[cs]es?_and_tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html | ||
303 | RedirectMatch ^/licen[cs]es?$ https://www.immae.eu/licenses_and_tipping.html | ||
304 | RedirectMatch ^/tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html | ||
305 | RedirectMatch ^/(mentions|mentions_legales|legal)$ https://www.immae.eu/mentions.html | ||
306 | RedirectMatch ^/CGU$ https://www.immae.eu/CGU | ||
307 | '' | ||
308 | ] | ||
309 | ; | ||
310 | }; | ||
311 | } | ||