1 { lib, pkgs, config, mylibs, myconfig, ... }:
3 mypkgs = pkgs.callPackage ../../packages.nix {
4 inherit (mylibs) checkEnv fetchedGit fetchedGithub;
6 cfg = config.services.myWebsites;
7 makeService = name: cfg: let
10 sslServerCert = "/var/lib/acme/${vhostConf.certName}/cert.pem";
11 sslServerKey = "/var/lib/acme/${vhostConf.certName}/key.pem";
12 sslServerChain = "/var/lib/acme/${vhostConf.certName}/fullchain.pem";
13 logFormat = "combinedVhost";
15 { ip = cfg.ip; port = 443; }
17 hostName = builtins.head vhostConf.hosts;
18 serverAliases = builtins.tail vhostConf.hosts or [];
19 documentRoot = vhostConf.root;
20 extraConfig = builtins.concatStringsSep "\n" vhostConf.extraConfig;
22 redirectVhost = { # Should go last, catchall http -> https redirect
23 listen = [ { ip = cfg.ip; port = 80; } ];
24 hostName = "redirectSSL";
25 serverAliases = [ "*" ];
27 logFormat = "combinedVhost";
28 documentRoot = "/var/lib/acme/acme-challenge";
31 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
32 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
33 # To redirect in specific "VirtualHost *:80", do
34 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
38 fallbackVhost = toVhost { # Should go first, default choice
40 hosts = ["eldiron.immae.eu" ];
42 extraConfig = [ "DirectoryIndex index.htm" ];
47 { ip = cfg.ip; port = 443; }
49 stateDir = "/run/httpd_${name}";
50 logPerVirtualHost = true;
51 multiProcessingModule = "worker";
52 adminAddr = "httpd@immae.eu";
53 logFormat = "combinedVhost";
54 extraModules = pkgs.lib.lists.unique (pkgs.lib.lists.flatten cfg.modules);
55 extraConfig = builtins.concatStringsSep "\n" cfg.extraConfig;
56 virtualHosts = [ fallbackVhost ]
57 ++ (pkgs.lib.attrsets.mapAttrsToList (n: v: toVhost v) cfg.vhostConfs)
60 makeServiceOptions = name: ip: {
61 enable = lib.mkEnableOption "enable websites in ${name}";
63 type = lib.types.string;
65 description = "${name} ip to listen to";
67 modules = lib.mkOption {
68 type = lib.types.listOf (lib.types.str);
71 extraConfig = lib.mkOption {
72 type = lib.types.listOf (lib.types.lines);
75 vhostConfs = lib.mkOption {
76 type = lib.types.attrsOf (lib.types.submodule {
78 certName = lib.mkOption { type = lib.types.string; };
79 hosts = lib.mkOption { type = lib.types.listOf lib.types.string; };
80 root = lib.mkOption { type = lib.types.nullOr lib.types.path; };
81 extraConfig = lib.mkOption { type = lib.types.listOf lib.types.lines; default = []; };
95 # sed -e "s/services\.httpd/services\.httpdProd/g" .nix-defexpr/channels/nixpkgs/nixos/modules/services/web-servers/apache-httpd/default.nix
96 # And removed users / groups
97 ./apache/httpd_prod.nix
98 ./apache/httpd_inte.nix
101 options.services.myWebsites = {
102 production = makeServiceOptions "production" myconfig.ips.production;
103 integration = makeServiceOptions "integration" myconfig.ips.integration;
104 tools = makeServiceOptions "tools" myconfig.ips.main;
106 apacheConfig = lib.mkOption {
107 type = lib.types.attrsOf (lib.types.submodule {
109 modules = lib.mkOption {
110 type = lib.types.listOf (lib.types.str);
113 extraConfig = lib.mkOption {
114 type = lib.types.nullOr lib.types.lines;
120 description = "Extra global config";
129 allowedTCPPorts = [ 80 443 ];
131 interfaces."eth0".ipv4.addresses = [
132 # 176.9.151.89 declared in nixops -> infra / tools
133 { address = myconfig.ips.production; prefixLength = 32; }
134 { address = myconfig.ips.integration; prefixLength = 32; }
138 nixpkgs.config.packageOverrides = oldpkgs: rec {
140 php72 = (oldpkgs.php72.override {
141 mysql.connector-c = pkgs.mariadb;
142 config.php.mysqlnd = false;
143 config.php.mysqli = false;
144 }).overrideAttrs(old: rec {
145 # Didn't manage to build with mysqli + mysql_config connector
146 configureFlags = old.configureFlags ++ [
147 "--with-mysqli=shared,mysqlnd"
149 # preConfigure = (old.preConfigure or "") + ''
150 # export CPPFLAGS="$CPPFLAGS -I${pkgs.mariadb}/include/mysql/server";
151 # sed -i -e 's/#include "mysqli_priv.h"/#include "mysqli_priv.h"\n#include <mysql_version.h>/' \
152 # ext/mysqli/mysqli.c ext/mysqli/mysqli_prop.c
155 phpPackages = oldpkgs.php72Packages.override { inherit php; };
158 services.myWebsites.Chloe.production.enable = cfg.production.enable;
159 services.myWebsites.Ludivine.production.enable = cfg.production.enable;
160 services.myWebsites.Aten.production.enable = cfg.production.enable;
161 services.myWebsites.PiedsJaloux.production.enable = cfg.production.enable;
162 services.myWebsites.Connexionswing.production.enable = cfg.production.enable;
164 services.myWebsites.Chloe.integration.enable = cfg.integration.enable;
165 services.myWebsites.Ludivine.integration.enable = cfg.integration.enable;
166 services.myWebsites.Aten.integration.enable = cfg.integration.enable;
167 services.myWebsites.PiedsJaloux.integration.enable = cfg.integration.enable;
168 services.myWebsites.Connexionswing.integration.enable = cfg.integration.enable;
170 services.myWebsites.apacheConfig = {
172 modules = [ "deflate" "filter" ];
174 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
178 modules = [ "macro" ];
181 modules = [ "ldap" "authnz_ldap" ];
183 extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
184 <IfModule ldap_module>
185 LDAPSharedCacheSize 500000
186 LDAPCacheEntries 1024
188 LDAPOpCacheEntries 1024
193 <IfModule authnz_ldap_module>
194 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS
195 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
196 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
198 AuthName "Authentification requise (Acces LDAP)"
199 AuthBasicProvider ldap
203 <Macro Stats %{domain}>
204 Alias /awstats /var/lib/goaccess/%{domain}
205 <Directory /var/lib/goaccess/%{domain}>
206 DirectoryIndex index.html
212 Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
218 modules = [ "http2" ];
220 Protocols h2 http/1.1
225 LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost
232 services.httpdProd = makeService "production" config.services.myWebsites.production;
233 services.myWebsites.production.modules = pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig);
234 services.myWebsites.production.extraConfig = (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig));
236 services.httpdInte = makeService "integration" config.services.myWebsites.integration;
237 services.myWebsites.integration.modules = pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig);
238 services.myWebsites.integration.extraConfig = (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig));
240 services.httpd = makeService "tools" config.services.myWebsites.tools;
241 services.myWebsites.tools.modules =
242 mypkgs.adminer.apache.modules ++
243 mypkgs.nextcloud.apache.modules ++
244 mypkgs.ympd.apache.modules ++
245 mypkgs.mantisbt.apache.modules ++
246 mypkgs.ttrss.apache.modules ++
247 mypkgs.roundcubemail.apache.modules ++
248 pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig);
249 services.myWebsites.tools.extraConfig = (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig));
250 # FIXME: move them all to separate modules
251 services.myWebsites.tools.vhostConfs.eldiron = {
252 certName = "eldiron";
253 hosts = ["eldiron.immae.eu" ];
255 extraConfig = [ "DirectoryIndex index.htm" ];
257 services.myWebsites.tools.vhostConfs.db-1 = {
258 certName = "eldiron";
259 hosts = ["db-1.immae.eu" ];
261 extraConfig = [ mypkgs.adminer.apache.vhostConf ];
263 services.myWebsites.tools.vhostConfs.tools = {
264 certName = "eldiron";
265 hosts = ["tools.immae.eu" ];
268 mypkgs.adminer.apache.vhostConf
269 mypkgs.ympd.apache.vhostConf
270 mypkgs.ttrss.apache.vhostConf
271 mypkgs.roundcubemail.apache.vhostConf
274 services.myWebsites.tools.vhostConfs.dav = {
275 certName = "eldiron";
276 hosts = ["dav.immae.eu" ];
279 mypkgs.infcloud.apache.vhostConf
280 mypkgs.davical.apache.vhostConf
283 services.myWebsites.tools.vhostConfs.cloud = {
284 certName = "eldiron";
285 hosts = ["cloud.immae.eu" ];
286 root = mypkgs.nextcloud.webRoot;
288 mypkgs.nextcloud.apache.vhostConf
291 services.myWebsites.tools.vhostConfs.git.extraConfig = [
292 mypkgs.mantisbt.apache.vhostConf
295 RewriteCond %{REQUEST_URI} ^/releases
296 RewriteRule /releases(.*) https://release.immae.eu$1 [P,L]