1 { lib, pkgs, config, mylibs, myconfig, ... }:
3 cfg = config.services.myWebsites;
4 www_root = "/run/current-system/webapps/_www";
5 theme_root = "/run/current-system/webapps/_theme";
6 makeService = name: cfg: let
9 sslServerCert = "/var/lib/acme/${vhostConf.certName}/cert.pem";
10 sslServerKey = "/var/lib/acme/${vhostConf.certName}/key.pem";
11 sslServerChain = "/var/lib/acme/${vhostConf.certName}/fullchain.pem";
12 logFormat = "combinedVhost";
14 { ip = cfg.ip; port = 443; }
16 hostName = builtins.head vhostConf.hosts;
17 serverAliases = builtins.tail vhostConf.hosts or [];
18 documentRoot = vhostConf.root;
19 extraConfig = builtins.concatStringsSep "\n" vhostConf.extraConfig;
22 listen = [ { ip = cfg.ip; port = 80; } ];
23 hostName = "nossl.immae.eu";
25 logFormat = "combinedVhost";
26 documentRoot = www_root;
28 <Directory ${www_root}>
29 DirectoryIndex nossl.html
34 RewriteRule ^/(.+) / [L]
38 redirectVhost = { # Should go last, catchall http -> https redirect
39 listen = [ { ip = cfg.ip; port = 80; } ];
40 hostName = "redirectSSL";
41 serverAliases = [ "*" ];
43 logFormat = "combinedVhost";
44 documentRoot = "/var/lib/acme/acme-challenge";
47 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
48 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
49 # To redirect in specific "VirtualHost *:80", do
50 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
54 fallbackVhost = toVhost { # Should go first, default choice
56 hosts = ["eldiron.immae.eu" ];
58 extraConfig = [ "DirectoryIndex index.htm" ];
63 { ip = cfg.ip; port = 443; }
65 stateDir = "/run/httpd_${name}";
66 logPerVirtualHost = true;
67 multiProcessingModule = "worker";
68 adminAddr = "httpd@immae.eu";
69 logFormat = "combinedVhost";
70 extraModules = pkgs.lib.lists.unique (pkgs.lib.lists.flatten cfg.modules);
71 extraConfig = builtins.concatStringsSep "\n" cfg.extraConfig;
72 virtualHosts = [ fallbackVhost ]
73 ++ lib.optionals (name == "tools") [ nosslVhost ]
74 ++ (pkgs.lib.attrsets.mapAttrsToList (n: v: toVhost v) cfg.vhostConfs)
77 makeServiceOptions = name: ip: {
78 enable = lib.mkEnableOption "enable websites in ${name}";
80 type = lib.types.string;
82 description = "${name} ip to listen to";
84 modules = lib.mkOption {
85 type = lib.types.listOf (lib.types.str);
88 extraConfig = lib.mkOption {
89 type = lib.types.listOf (lib.types.lines);
92 vhostConfs = lib.mkOption {
93 type = lib.types.attrsOf (lib.types.submodule {
95 certName = lib.mkOption { type = lib.types.string; };
96 hosts = lib.mkOption { type = lib.types.listOf lib.types.string; };
97 root = lib.mkOption { type = lib.types.nullOr lib.types.path; };
98 extraConfig = lib.mkOption { type = lib.types.listOf lib.types.lines; default = []; };
103 makeModules = cfg: pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig);
104 makeExtraConfig = cfg: (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig));
119 ./ftp/denisejerome.nix
134 # sed -e "s/services\.httpd/services\.httpdProd/g" .nix-defexpr/channels/nixpkgs/nixos/modules/services/web-servers/apache-httpd/default.nix
136 # And removed users / groups
137 ./apache/httpd_prod.nix
138 ./apache/httpd_inte.nix
139 # except for this one for users/groups
140 ./apache/httpd_tools.nix
141 # Adapted from base phpfpm
145 options.services.myWebsites = {
146 production = makeServiceOptions "production" myconfig.ips.production;
147 integration = makeServiceOptions "integration" myconfig.ips.integration;
148 tools = makeServiceOptions "tools" myconfig.ips.main;
150 apacheConfig = lib.mkOption {
151 type = lib.types.attrsOf (lib.types.submodule {
153 modules = lib.mkOption {
154 type = lib.types.listOf (lib.types.str);
157 extraConfig = lib.mkOption {
158 type = lib.types.nullOr lib.types.lines;
164 description = "Extra global config";
173 allowedTCPPorts = [ 80 443 ];
175 interfaces."eth0".ipv4.addresses = [
176 # 176.9.151.89 declared in nixops -> infra / tools
177 { address = myconfig.ips.production; prefixLength = 32; }
178 { address = myconfig.ips.integration; prefixLength = 32; }
182 nixpkgs.config.packageOverrides = oldpkgs: rec {
184 php72 = (oldpkgs.php72.override {
185 mysql.connector-c = pkgs.mariadb;
186 config.php.mysqlnd = false;
187 config.php.mysqli = false;
188 }).overrideAttrs(old: rec {
189 # Didn't manage to build with mysqli + mysql_config connector
190 configureFlags = old.configureFlags ++ [
191 "--with-mysqli=shared,mysqlnd"
193 # preConfigure = (old.preConfigure or "") + ''
194 # export CPPFLAGS="$CPPFLAGS -I${pkgs.mariadb}/include/mysql/server";
195 # sed -i -e 's/#include "mysqli_priv.h"/#include "mysqli_priv.h"\n#include <mysql_version.h>/' \
196 # ext/mysqli/mysqli.c ext/mysqli/mysqli_prop.c
199 phpPackages = oldpkgs.php72Packages.override { inherit php; };
200 composerEnv = import ./commons/composer-env.nix {
201 inherit (pkgs) stdenv writeTextFile fetchurl php unzip;
205 services.myWebsites.tools.databases.enable = true;
206 services.myWebsites.tools.tools.enable = true;
207 services.myWebsites.tools.dav.enable = true;
208 services.myWebsites.tools.cloud.enable = true;
209 services.myWebsites.tools.git.enable = true;
210 services.myWebsites.tools.mastodon.enable = true;
211 services.myWebsites.tools.mediagoblin.enable = true;
212 services.myWebsites.tools.diaspora.enable = true;
213 services.myWebsites.tools.etherpad-lite.enable = true;
214 services.myWebsites.tools.peertube.enable = true;
216 services.myWebsites.Chloe.production.enable = cfg.production.enable;
217 services.myWebsites.Ludivine.production.enable = cfg.production.enable;
218 services.myWebsites.Aten.production.enable = cfg.production.enable;
219 services.myWebsites.PiedsJaloux.production.enable = cfg.production.enable;
220 services.myWebsites.Connexionswing.production.enable = cfg.production.enable;
221 services.myWebsites.Jerome.production.enable = cfg.production.enable;
222 services.myWebsites.Nassime.production.enable = cfg.production.enable;
223 services.myWebsites.Florian.production.enable = cfg.production.enable;
224 services.myWebsites.DeniseJerome.production.enable = cfg.production.enable;
225 services.myWebsites.Emilia.production.enable = cfg.production.enable;
226 services.myWebsites.Capitaines.production.enable = cfg.production.enable;
227 services.myWebsites.Immae.production.enable = cfg.production.enable;
228 services.myWebsites.Release.production.enable = cfg.production.enable;
229 services.myWebsites.Temp.production.enable = cfg.production.enable;
231 services.myWebsites.Chloe.integration.enable = cfg.integration.enable;
232 services.myWebsites.Ludivine.integration.enable = cfg.integration.enable;
233 services.myWebsites.Aten.integration.enable = cfg.integration.enable;
234 services.myWebsites.PiedsJaloux.integration.enable = cfg.integration.enable;
235 services.myWebsites.Connexionswing.integration.enable = cfg.integration.enable;
236 services.myWebsites.TellesFlorian.integration.enable = true;
237 services.myWebsites.Florian.integration.enable = true;
239 services.myWebsites.apacheConfig = {
241 modules = [ "deflate" "filter" ];
243 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
247 modules = [ "macro" ];
251 <Macro Stats %{domain}>
252 Alias /awstats /var/lib/goaccess/%{domain}
253 <Directory /var/lib/goaccess/%{domain}>
254 DirectoryIndex index.html
260 Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
266 modules = [ "ldap" "authnz_ldap" ];
268 <IfModule ldap_module>
269 LDAPSharedCacheSize 500000
270 LDAPCacheEntries 1024
272 LDAPOpCacheEntries 1024
277 <IfModule authnz_ldap_module>
278 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS
279 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
280 AuthLDAPBindPassword "${myconfig.env.httpd.ldap.password}"
282 AuthName "Authentification requise (Acces LDAP)"
283 AuthBasicProvider ldap
290 ErrorDocument 500 /maintenance_immae.html
291 ErrorDocument 501 /maintenance_immae.html
292 ErrorDocument 502 /maintenance_immae.html
293 ErrorDocument 503 /maintenance_immae.html
294 ErrorDocument 504 /maintenance_immae.html
295 Alias /maintenance_immae.html ${www_root}/maintenance_immae.html
296 ProxyPass /maintenance_immae.html !
298 AliasMatch "(.*)/googleb6d69446ff4ca3e5.html" ${www_root}/googleb6d69446ff4ca3e5.html
299 <Directory ${www_root}>
307 <Macro Apaxy %{folder} %{ignored}>
308 Alias /theme ${theme_root}
309 <Directory ${theme_root}>
316 <Directory %{folder}>
321 # Inspired from Apaxy by @adamwhitcroft
323 IndexOptions +Charset=UTF-8 +FancyIndexing +IgnoreCase +FoldersFirst +XHTML +HTMLTable +SuppressRules +SuppressDescription +NameWidth=* +IconsAreLinks +ShowForbidden
325 IndexHeadInsert "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />"
328 IndexIgnore /theme .htaccess %{ignored}
330 AddIcon /theme/icons/blank.png ^^BLANKICON^^
331 AddIcon /theme/icons/folder.png ^^DIRECTORY^^
332 AddIcon /theme/icons/folder-home.png ..
334 AddIconByType (TXT,/theme/icons/text.png) text/*
335 AddIconByType (IMG,/theme/icons/image.png) image/*
336 AddIconByType (SND,/theme/icons/audio.png) audio/*
337 AddIconByType (VID,/theme/icons/video.png) video/*
339 AddIcon /theme/icons/archive.png .7z .bz2 .cab .gz .tar
340 AddIcon /theme/icons/audio.png .aac .aif .aifc .aiff .ape .au .flac .iff .m4a .mid .mp3 .mpa .ra .wav .wma .f4a .f4b .oga .ogg .xm .it .s3m .mod
341 AddIcon /theme/icons/bin.png .bin .hex
342 AddIcon /theme/icons/bmp.png .bmp
343 AddIcon /theme/icons/c.png .c
344 AddIcon /theme/icons/calc.png .xlsx .xlsm .xltx .xltm .xlam .xlr .xls .csv
345 AddIcon /theme/icons/cd.png .iso
346 AddIcon /theme/icons/cpp.png .cpp
347 AddIcon /theme/icons/css.png .css .sass .scss
348 AddIcon /theme/icons/deb.png .deb
349 AddIcon /theme/icons/doc.png .doc .docx .docm .dot .dotx .dotm .log .msg .odt .pages .rtf .tex .wpd .wps
350 AddIcon /theme/icons/draw.png .svg .svgz
351 AddIcon /theme/icons/eps.png .ai .eps
352 AddIcon /theme/icons/exe.png .exe
353 AddIcon /theme/icons/gif.png .gif
354 AddIcon /theme/icons/h.png .h
355 AddIcon /theme/icons/html.png .html .xhtml .shtml .htm .URL .url
356 AddIcon /theme/icons/ico.png .ico
357 AddIcon /theme/icons/java.png .jar
358 AddIcon /theme/icons/jpg.png .jpg .jpeg .jpe
359 AddIcon /theme/icons/js.png .js .json
360 AddIcon /theme/icons/markdown.png .md
361 AddIcon /theme/icons/package.png .pkg .dmg
362 AddIcon /theme/icons/pdf.png .pdf
363 AddIcon /theme/icons/php.png .php .phtml
364 AddIcon /theme/icons/playlist.png .m3u .m3u8 .pls .pls8
365 AddIcon /theme/icons/png.png .png
366 AddIcon /theme/icons/ps.png .ps
367 AddIcon /theme/icons/psd.png .psd
368 AddIcon /theme/icons/py.png .py
369 AddIcon /theme/icons/rar.png .rar
370 AddIcon /theme/icons/rb.png .rb
371 AddIcon /theme/icons/rpm.png .rpm
372 AddIcon /theme/icons/rss.png .rss
373 AddIcon /theme/icons/script.png .bat .cmd .sh
374 AddIcon /theme/icons/sql.png .sql
375 AddIcon /theme/icons/tiff.png .tiff .tif
376 AddIcon /theme/icons/text.png .txt .nfo
377 AddIcon /theme/icons/video.png .asf .asx .avi .flv .mkv .mov .mp4 .mpg .rm .srt .swf .vob .wmv .m4v .f4v .f4p .ogv
378 AddIcon /theme/icons/xml.png .xml
379 AddIcon /theme/icons/zip.png .zip
380 DefaultIcon /theme/icons/default.png
382 HeaderName /theme/header.html
383 ReadmeName /theme/footer.html
384 IndexStyleSheet /theme/style.css
390 modules = [ "http2" ];
392 Protocols h2 http/1.1
397 LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost
402 system.activationScripts = {
404 install -d -m 0755 /var/lib/acme/acme-challenge
405 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions
406 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/adminer
407 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt
408 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/davical
412 system.extraSystemBuilderCmds = let
413 adminer = pkgs.callPackage ./commons/adminer.nix {};
415 mkdir -p $out/webapps
416 ln -s ${../../www} $out/webapps/_www
417 ln -s ${./apache/theme} $out/webapps/_theme
418 ln -s ${adminer.webRoot} $out/webapps/${adminer.apache.webappName}
421 services.myPhpfpm = {
422 phpPackage = pkgs.php;
424 session.save_path = "/var/lib/php/sessions"
426 session.gc_maxlifetime = 60*60*24*15
427 session.cache_expire = 60*24*30
434 services.httpdProd = makeService "production" config.services.myWebsites.production;
435 services.myWebsites.production.modules = makeModules cfg;
436 services.myWebsites.production.extraConfig = makeExtraConfig cfg;
438 services.httpdInte = makeService "integration" config.services.myWebsites.integration;
439 services.myWebsites.integration.modules = makeModules cfg;
440 services.myWebsites.integration.extraConfig = makeExtraConfig cfg;
442 services.httpdTools = makeService "tools" config.services.myWebsites.tools;
443 services.myWebsites.tools.modules = makeModules cfg;
444 services.myWebsites.tools.extraConfig = makeExtraConfig cfg ++
446 RedirectMatch ^/licen[cs]es?_et_tip(ping)?$ https://www.immae.eu/licences_et_tip.html
447 RedirectMatch ^/licen[cs]es?_and_tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html
448 RedirectMatch ^/licen[cs]es?$ https://www.immae.eu/licenses_and_tipping.html
449 RedirectMatch ^/tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html
450 RedirectMatch ^/(mentions|mentions_legales|legal)$ https://www.immae.eu/mentions.html
451 RedirectMatch ^/CGU$ https://www.immae.eu/CGU