]>
Commit | Line | Data |
---|---|---|
1a64deeb | 1 | { lib, pkgs, config, mypackages-lib, ... }: |
4288c2f2 | 2 | let |
750fe5a4 | 3 | www_root = ./_www; |
1a64deeb | 4 | theme_root = (mypackages-lib.apache-theme {}).theme; |
4288c2f2 | 5 | apacheConfig = { |
1a64deeb IB |
6 | shutdownconfig = { |
7 | # Only give 5 seconds to workers to finish their work | |
8 | extraConfig = '' | |
9 | GracefulShutdownTimeout 5 | |
10 | ''; | |
11 | }; | |
9271611c IB |
12 | cache = { |
13 | # This setting permits to ignore time-based cache for files in the | |
14 | # nix store: | |
15 | # If a client requires an If-Modified-Since from timestamp 1, then | |
16 | # this header is removed, and if the response contains a | |
17 | # too old Last-Modified tag, then it is removed too | |
18 | extraConfig = '' | |
19 | <If "%{HTTP:If-Modified-Since} =~ /01 Jan 1970 00:00:01/" > | |
20 | RequestHeader unset If-Modified-Since | |
21 | </If> | |
22 | Header unset Last-Modified "expr=%{LAST_MODIFIED} < 19991231235959" | |
23 | ''; | |
24 | }; | |
4288c2f2 IB |
25 | gzip = { |
26 | modules = [ "deflate" "filter" ]; | |
27 | extraConfig = '' | |
28 | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript | |
29 | ''; | |
30 | }; | |
31 | macros = { | |
32 | modules = [ "macro" ]; | |
33 | }; | |
34 | stats = { | |
35 | extraConfig = '' | |
36 | <Macro Stats %{domain}> | |
37 | Alias /webstats ${config.services.webstats.dataDir}/%{domain} | |
38 | <Directory ${config.services.webstats.dataDir}/%{domain}> | |
39 | DirectoryIndex index.html | |
40 | AllowOverride None | |
41 | Require all granted | |
42 | </Directory> | |
43 | <Location /webstats> | |
44 | Use LDAPConnect | |
45 | Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu | |
46 | </Location> | |
47 | </Macro> | |
48 | ''; | |
49 | }; | |
50 | ldap = { | |
51 | modules = [ "ldap" "authnz_ldap" ]; | |
52 | extraConfig = '' | |
53 | <IfModule ldap_module> | |
54 | LDAPSharedCacheSize 500000 | |
55 | LDAPCacheEntries 1024 | |
56 | LDAPCacheTTL 600 | |
57 | LDAPOpCacheEntries 1024 | |
58 | LDAPOpCacheTTL 600 | |
59 | </IfModule> | |
60 | ||
da30ae4f | 61 | Include ${config.secrets.fullPaths."apache-ldap"} |
4288c2f2 IB |
62 | ''; |
63 | }; | |
64 | global = { | |
d3452fc5 IB |
65 | extraConfig = '' |
66 | ErrorDocument 500 /maintenance_immae.html | |
67 | ErrorDocument 501 /maintenance_immae.html | |
68 | ErrorDocument 502 /maintenance_immae.html | |
69 | ErrorDocument 503 /maintenance_immae.html | |
70 | ErrorDocument 504 /maintenance_immae.html | |
71 | Alias /maintenance_immae.html ${www_root}/maintenance_immae.html | |
72 | ProxyPass /maintenance_immae.html ! | |
73 | ||
74 | AliasMatch "(.*)/googleb6d69446ff4ca3e5.html" ${www_root}/googleb6d69446ff4ca3e5.html | |
75 | <Directory ${www_root}> | |
76 | AllowOverride None | |
77 | Require all granted | |
78 | </Directory> | |
79 | ''; | |
4288c2f2 IB |
80 | }; |
81 | apaxy = { | |
1a64deeb | 82 | extraConfig = (mypackages-lib.apache-theme { inherit theme_root; }).apacheConfig; |
4288c2f2 IB |
83 | }; |
84 | http2 = { | |
85 | modules = [ "http2" ]; | |
86 | extraConfig = '' | |
87 | Protocols h2 http/1.1 | |
88 | ''; | |
89 | }; | |
90 | customLog = { | |
91 | extraConfig = '' | |
494d0718 | 92 | LogFormat "%{Host}i:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedVhost |
4288c2f2 IB |
93 | ''; |
94 | }; | |
95 | }; | |
96 | makeModules = lib.lists.flatten (lib.attrsets.mapAttrsToList (n: v: v.modules or []) apacheConfig); | |
97 | makeExtraConfig = (builtins.filter (x: x != null) (lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) apacheConfig)); | |
36861e95 IB |
98 | moomin = let |
99 | lines = lib.splitString "\n" (lib.fileContents ./moomin.txt); | |
100 | pad = width: str: let | |
101 | padWidth = width - lib.stringLength str; | |
102 | padding = lib.concatStrings (lib.genList (lib.const "0") padWidth); | |
103 | in lib.optionalString (padWidth > 0) padding + str; | |
104 | in | |
105 | lib.imap0 (i: e: ''Header always set "X-Moomin-${pad 2 (builtins.toString i)}" "${e}"'') lines; | |
4288c2f2 | 106 | in |
f8026b6e | 107 | { |
1a64deeb IB |
108 | imports = [ |
109 | ./immae/production.nix | |
110 | ./immae/release.nix | |
111 | ||
112 | # Tools | |
113 | ./assets | |
114 | ./cloud | |
115 | ./cloud/farm.nix | |
116 | ./cryptpad | |
117 | ./cryptpad/farm.nix | |
118 | ./commento | |
119 | ./dav | |
120 | ./vpn | |
121 | ./db | |
122 | ./diaspora | |
123 | ./ether | |
124 | ./git | |
125 | ./im | |
126 | ./mastodon | |
127 | ./mgoblin | |
128 | ./peertube | |
129 | ./performance | |
130 | ./tools | |
131 | ||
132 | ./stats | |
133 | ./visio | |
134 | ./kanboard/farm.nix | |
135 | ||
136 | # Games | |
137 | ./games/codenames | |
138 | ./games/terraforming-mars | |
139 | ]; | |
140 | ||
d3452fc5 | 141 | options.myServices.websites.enable = lib.mkEnableOption "enable websites"; |
4288c2f2 | 142 | |
8415083e | 143 | config = lib.mkIf config.myServices.websites.enable { |
1a64deeb IB |
144 | myServices.dns.zones."immae.eu".subdomains = with config.myServices.dns.helpers; |
145 | { | |
146 | games = ips servers.eldiron.ips.main; | |
147 | nossl = ips servers.eldiron.ips.main; | |
148 | }; | |
149 | ||
150 | myServices.chatonsProperties.hostings.web = { | |
151 | file.datetime = "2022-08-22T01:30:00"; | |
152 | hosting = { | |
153 | name = "Hébergement Web"; | |
154 | description = "Service d'hébergement web avec php/mysql/postgresql"; | |
155 | website = "https://www.immae.eu"; | |
156 | status.level = "OK"; | |
157 | status.description = "OK"; | |
158 | registration.load = "OPEN"; | |
159 | install.type = "PACKAGE"; | |
160 | }; | |
161 | software = { | |
162 | name = "Apache Httpd"; | |
163 | website = "https://httpd.apache.org/"; | |
164 | license.url = "https://www.apache.org/licenses/"; | |
165 | license.name = "Apache License Version 2"; | |
166 | version = pkgs.apacheHttpd.version; | |
167 | source.url = "https://httpd.apache.org/download.cgi"; | |
168 | modules = "openssh,pure-ftpd"; | |
169 | }; | |
170 | }; | |
4288c2f2 IB |
171 | users.users.wwwrun.extraGroups = [ "keys" ]; |
172 | networking.firewall.allowedTCPPorts = [ 80 443 ]; | |
173 | ||
4c4652aa | 174 | secrets.keys."apache-ldap" = { |
4288c2f2 IB |
175 | user = "wwwrun"; |
176 | group = "wwwrun"; | |
177 | permissions = "0400"; | |
178 | text = '' | |
179 | <Macro LDAPConnect> | |
180 | <IfModule authnz_ldap_module> | |
181 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu STARTTLS | |
182 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | |
ab8f306d | 183 | AuthLDAPBindPassword "${config.myEnv.httpd.ldap.password}" |
4288c2f2 IB |
184 | AuthType Basic |
185 | AuthName "Authentification requise (Acces LDAP)" | |
186 | AuthBasicProvider ldap | |
187 | </IfModule> | |
188 | </Macro> | |
189 | ''; | |
4c4652aa | 190 | }; |
4288c2f2 IB |
191 | |
192 | system.activationScripts = { | |
193 | httpd = '' | |
3ffa15ba | 194 | install -d -m 0755 /var/lib/acme/acme-challenges |
4288c2f2 IB |
195 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions |
196 | ''; | |
197 | }; | |
198 | ||
199 | services.phpfpm = { | |
4288c2f2 IB |
200 | phpOptions = '' |
201 | session.save_path = "/var/lib/php/sessions" | |
202 | post_max_size = 20M | |
203 | ; 15 days (seconds) | |
204 | session.gc_maxlifetime = 1296000 | |
205 | ; 30 days (minutes) | |
206 | session.cache_expire = 43200 | |
207 | ''; | |
5400b9b6 IB |
208 | settings = { |
209 | log_level = "notice"; | |
210 | }; | |
4288c2f2 IB |
211 | }; |
212 | ||
29f8cb85 | 213 | services.websites.env.production = { |
4288c2f2 | 214 | enable = true; |
1a64deeb | 215 | moduleType = "container"; |
4288c2f2 | 216 | adminAddr = "httpd@immae.eu"; |
1a64deeb IB |
217 | bindMounts."/var/lib/ftp" = {}; |
218 | # FIXME: Bind directly the needed files | |
219 | bindMounts."/var/secrets" = {}; | |
220 | bindMounts."/var/lib/goaccess" = {}; | |
221 | bindMounts."/var/lib/acme" = {}; | |
222 | bindMounts."/run/phpfpm" = {}; | |
4288c2f2 | 223 | ips = |
ab8f306d | 224 | let ips = config.myEnv.servers.eldiron.ips.production; |
1a64deeb | 225 | in (ips.ip4 or []) ++ (ips.ip6 or []); |
4288c2f2 IB |
226 | modules = makeModules; |
227 | extraConfig = makeExtraConfig; | |
228 | fallbackVhost = { | |
229 | certName = "eldiron"; | |
230 | hosts = ["eldiron.immae.eu" ]; | |
231 | root = www_root; | |
232 | extraConfig = [ "DirectoryIndex index.htm" ]; | |
233 | }; | |
234 | }; | |
235 | ||
29f8cb85 | 236 | services.websites.env.integration = { |
4288c2f2 | 237 | enable = true; |
1a64deeb | 238 | moduleType = "container"; |
4288c2f2 | 239 | adminAddr = "httpd@immae.eu"; |
1a64deeb IB |
240 | bindMounts."/var/lib/ftp" = {}; |
241 | bindMounts."/var/secrets" = {}; | |
242 | bindMounts."/var/lib/goaccess" = {}; | |
243 | bindMounts."/var/lib/acme" = {}; | |
244 | bindMounts."/run/phpfpm" = {}; | |
4288c2f2 | 245 | ips = |
ab8f306d | 246 | let ips = config.myEnv.servers.eldiron.ips.integration; |
1a64deeb | 247 | in (ips.ip4 or []) ++ (ips.ip6 or []); |
4288c2f2 | 248 | modules = makeModules; |
36861e95 | 249 | extraConfig = makeExtraConfig ++ moomin; |
4288c2f2 | 250 | fallbackVhost = { |
1a64deeb | 251 | certName = "integration"; |
4288c2f2 IB |
252 | hosts = ["eldiron.immae.eu" ]; |
253 | root = www_root; | |
254 | extraConfig = [ "DirectoryIndex index.htm" ]; | |
255 | }; | |
1a64deeb | 256 | watchPaths = [ config.secrets.fullPaths."apache-ldap" ]; |
4288c2f2 IB |
257 | }; |
258 | ||
29f8cb85 | 259 | services.websites.env.tools = { |
4288c2f2 | 260 | enable = true; |
1a64deeb | 261 | moduleType = "main"; |
4288c2f2 | 262 | adminAddr = "httpd@immae.eu"; |
4288c2f2 | 263 | ips = |
ab8f306d | 264 | let ips = config.myEnv.servers.eldiron.ips.main; |
1a64deeb | 265 | in (ips.ip4 or []) ++ (ips.ip6 or []); |
4288c2f2 IB |
266 | modules = makeModules; |
267 | extraConfig = makeExtraConfig ++ | |
268 | [ '' | |
269 | RedirectMatch ^/licen[cs]es?_et_tip(ping)?$ https://www.immae.eu/licences_et_tip.html | |
270 | RedirectMatch ^/licen[cs]es?_and_tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html | |
271 | RedirectMatch ^/licen[cs]es?$ https://www.immae.eu/licenses_and_tipping.html | |
272 | RedirectMatch ^/tip(ping)?$ https://www.immae.eu/licenses_and_tipping.html | |
273 | RedirectMatch ^/(mentions|mentions_legales|legal)$ https://www.immae.eu/mentions.html | |
274 | RedirectMatch ^/CGU$ https://www.immae.eu/CGU | |
275 | '' | |
276 | ]; | |
277 | nosslVhost = { | |
278 | enable = true; | |
279 | host = "nossl.immae.eu"; | |
1a64deeb | 280 | root = ./nossl; |
4288c2f2 IB |
281 | }; |
282 | fallbackVhost = { | |
283 | certName = "eldiron"; | |
284 | hosts = ["eldiron.immae.eu" ]; | |
285 | root = www_root; | |
286 | extraConfig = [ "DirectoryIndex index.htm" ]; | |
287 | }; | |
1a64deeb | 288 | watchPaths = [ config.secrets.fullPaths."apache-ldap" ]; |
4288c2f2 IB |
289 | }; |
290 | ||
4288c2f2 | 291 | myServices.websites = { |
d3452fc5 IB |
292 | immae = { |
293 | production.enable = true; | |
294 | release.enable = true; | |
d3452fc5 | 295 | }; |
f8026b6e | 296 | |
4c42e0be | 297 | tools.assets.enable = true; |
4288c2f2 | 298 | tools.cloud.enable = true; |
6338573a | 299 | tools.commento.enable = true; |
8c91e92c | 300 | tools.cryptpad.enable = true; |
4288c2f2 IB |
301 | tools.dav.enable = true; |
302 | tools.db.enable = true; | |
303 | tools.diaspora.enable = true; | |
304 | tools.etherpad-lite.enable = true; | |
305 | tools.git.enable = true; | |
306 | tools.mastodon.enable = true; | |
307 | tools.mediagoblin.enable = true; | |
308 | tools.peertube.enable = true; | |
a97118c4 | 309 | tools.performance.enable = true; |
4288c2f2 | 310 | tools.tools.enable = true; |
afcc5de0 | 311 | tools.email.enable = true; |
a565d58b | 312 | tools.stats.enable = false; |
1a64deeb | 313 | tools.visio.enable = true; |
de6002a1 IB |
314 | |
315 | games.codenames.enable = true; | |
f036e975 | 316 | games.terraforming-mars.enable = true; |
4288c2f2 IB |
317 | }; |
318 | }; | |
f8026b6e | 319 | } |