1 { lib, pkgs, config, mylibs, myconfig, ... }:
3 cfg = config.services.myWebsites;
4 makeService = name: cfg: let
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";
12 { ip = cfg.ip; port = 443; }
14 hostName = builtins.head vhostConf.hosts;
15 serverAliases = builtins.tail vhostConf.hosts or [];
16 documentRoot = vhostConf.root;
17 extraConfig = builtins.concatStringsSep "\n" vhostConf.extraConfig;
22 { ip = cfg.ip; port = 443; }
24 stateDir = "/run/httpd_${name}";
25 logPerVirtualHost = true;
26 multiProcessingModule = "worker";
27 adminAddr = "httpd@immae.eu";
28 logFormat = "combinedVhost";
29 extraModules = pkgs.lib.lists.unique (pkgs.lib.lists.flatten cfg.modules);
30 extraConfig = builtins.concatStringsSep "\n" cfg.extraConfig;
31 virtualHosts = pkgs.lib.attrsets.mapAttrsToList (n: v: toVhost v) cfg.vhostConfs;
33 makeServiceOptions = name: ip: {
34 enable = lib.mkEnableOption "enable websites in ${name}";
36 type = lib.types.string;
38 description = "${name} ip to listen to";
40 modules = lib.mkOption {
41 type = lib.types.listOf (lib.types.str);
44 extraConfig = lib.mkOption {
45 type = lib.types.listOf (lib.types.lines);
48 vhostConfs = lib.mkOption {
49 type = lib.types.attrsOf (lib.types.submodule {
51 certName = lib.mkOption { type = lib.types.string; };
52 hosts = lib.mkOption { type = lib.types.listOf lib.types.string; };
53 root = lib.mkOption { type = lib.types.nullOr lib.types.path; };
54 extraConfig = lib.mkOption { type = lib.types.listOf lib.types.lines; default = []; };
68 # sed -e "s/services\.httpd/services\.httpdProd/g" .nix-defexpr/channels/nixpkgs/nixos/modules/services/web-servers/apache-httpd/default.nix
69 # And removed users / groups
70 ./apache/httpd_prod.nix
71 ./apache/httpd_inte.nix
74 options.services.myWebsites = {
75 production = makeServiceOptions "production" myconfig.ips.production;
76 integration = makeServiceOptions "integration" myconfig.ips.integration;
78 apacheConfig = lib.mkOption {
79 type = lib.types.attrsOf (lib.types.submodule {
81 modules = lib.mkOption {
82 type = lib.types.listOf (lib.types.str);
85 extraConfig = lib.mkOption {
86 type = lib.types.nullOr lib.types.lines;
92 description = "Extra global config";
101 allowedTCPPorts = [ 80 443 ];
103 interfaces."eth0".ipv4.addresses = [
104 # 176.9.151.89 declared in nixops -> infra / tools
105 { address = myconfig.ips.production; prefixLength = 32; }
106 { address = myconfig.ips.integration; prefixLength = 32; }
110 services.myWebsites.Chloe.production.enable = cfg.production.enable;
111 services.myWebsites.Ludivine.production.enable = cfg.production.enable;
112 services.myWebsites.Aten.production.enable = cfg.production.enable;
113 services.myWebsites.PiedsJaloux.production.enable = cfg.production.enable;
114 services.myWebsites.Connexionswing.production.enable = cfg.production.enable;
116 services.myWebsites.Chloe.integration.enable = cfg.integration.enable;
117 services.myWebsites.Ludivine.integration.enable = cfg.integration.enable;
118 services.myWebsites.Aten.integration.enable = cfg.integration.enable;
119 services.myWebsites.PiedsJaloux.integration.enable = cfg.integration.enable;
120 services.myWebsites.Connexionswing.integration.enable = cfg.integration.enable;
122 services.myWebsites.apacheConfig = {
124 modules = [ "deflate" "filter" ];
126 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
130 modules = [ "macro" ];
133 modules = [ "ldap" "authnz_ldap" ];
135 extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
136 <IfModule ldap_module>
137 LDAPSharedCacheSize 500000
138 LDAPCacheEntries 1024
140 LDAPOpCacheEntries 1024
145 <IfModule authnz_ldap_module>
146 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS
147 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
148 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
150 AuthName "Authentification requise (Acces LDAP)"
151 AuthBasicProvider ldap
155 <Macro Stats %{domain}>
156 Alias /awstats /var/lib/goaccess/%{domain}
157 <Directory /var/lib/goaccess/%{domain}>
158 DirectoryIndex index.html
164 Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
170 modules = [ "http2" ];
172 Protocols h2 http/1.1
177 LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost
184 services.httpdProd = makeService "production" config.services.myWebsites.production;
185 services.myWebsites.production.modules = pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig);
186 services.myWebsites.production.extraConfig = (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig));
188 services.httpdInte = makeService "integration" config.services.myWebsites.integration;
189 services.myWebsites.integration.modules = pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) cfg.apacheConfig);
190 services.myWebsites.integration.extraConfig = (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) cfg.apacheConfig));