]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/connexionswing/builder.nix
1224420b6e57c8a3488d4e3bc0bcf2e06012915a
[perso/Immae/Config/Nix.git] / modules / private / websites / connexionswing / builder.nix
1 { apacheUser, apacheGroup, connexionswing, pkgs, phpPackages, config }:
2 rec {
3 app = connexionswing.override { inherit (config) environment; };
4 keys = [{
5 dest = "webapps/${app.environment}-connexionswing";
6 user = apacheUser;
7 group = apacheGroup;
8 permissions = "0400";
9 text = ''
10 # This file is auto-generated during the composer install
11 parameters:
12 database_host: ${config.mysql.host}
13 database_port: ${config.mysql.port}
14 database_name: ${config.mysql.name}
15 database_user: ${config.mysql.user}
16 database_password: ${config.mysql.password}
17 database_server_version: ${pkgs.mariadb.mysqlVersion}
18 mailer_transport: sendmail
19 mailer_host: null
20 mailer_user: null
21 mailer_password: null
22 subscription_email: ${config.email}
23 allow_robots: true
24 secret: ${config.secret}
25 ${if app.environment == "prod" then ''
26 services:
27 swiftmailer.mailer.default.transport:
28 class: Swift_SendmailTransport
29 arguments: ['/run/wrappers/bin/sendmail -bs']
30 '' else ""}
31 '';
32 }];
33 phpFpm = rec {
34 preStart = ''
35 if [ ! -f "${app.varDir}/currentWebappDir" -o \
36 ! -f "${app.varDir}/currentKey" -o \
37 "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
38 || ! sha512sum -c --status ${app.varDir}/currentKey; then
39 pushd ${app} > /dev/null
40 /run/wrappers/bin/sudo -u ${apacheUser} ./bin/console --env=${app.environment} cache:clear --no-warmup
41 popd > /dev/null
42 echo -n "${app}" > ${app.varDir}/currentWebappDir
43 sha512sum /var/secrets/webapps/${app.environment}-connexionswing > ${app.varDir}/currentKey
44 fi
45 '';
46 serviceDeps = [ "mysql.service" ];
47 socket = "/var/run/phpfpm/connexionswing-${app.environment}.sock";
48 phpConfig = ''
49 extension=${phpPackages.imagick}/lib/php/extensions/imagick.so
50 '';
51 pool = ''
52 listen = ${socket}
53 user = ${apacheUser}
54 group = ${apacheGroup}
55 listen.owner = ${apacheUser}
56 listen.group = ${apacheGroup}
57 php_admin_value[upload_max_filesize] = 20M
58 php_admin_value[post_max_size] = 20M
59 ;php_admin_flag[log_errors] = on
60 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/var/secrets/webapps/${app.environment}-connexionswing:${app}:${app.varDir}:/tmp"
61 php_admin_value[session.save_path] = "${app.varDir}/phpSessions"
62 ${if app.environment == "dev" then ''
63 pm = ondemand
64 pm.max_children = 5
65 pm.process_idle_timeout = 60
66 env[SYMFONY_DEBUG_MODE] = "yes"
67 '' else ''
68 pm = dynamic
69 pm.max_children = 20
70 pm.start_servers = 2
71 pm.min_spare_servers = 1
72 pm.max_spare_servers = 3
73 ''}'';
74 };
75 apache = rec {
76 modules = [ "proxy_fcgi" ];
77 webappName = "connexionswing_${app.environment}";
78 root = "/run/current-system/webapps/${webappName}";
79 vhostConf = ''
80 <FilesMatch "\.php$">
81 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
82 </FilesMatch>
83
84 <Directory ${app.varDir}/medias>
85 Options FollowSymLinks
86 AllowOverride None
87 Require all granted
88 </Directory>
89
90 <Directory ${app.varDir}/uploads>
91 Options FollowSymLinks
92 AllowOverride None
93 Require all granted
94 </Directory>
95
96 ${if app.environment == "dev" then ''
97 <Location />
98 Use LDAPConnect
99 Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
100 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>"
101 </Location>
102
103 <Directory ${root}>
104 Options Indexes FollowSymLinks MultiViews Includes
105 AllowOverride None
106 Require all granted
107
108 DirectoryIndex app_dev.php
109
110 <IfModule mod_negotiation.c>
111 Options -MultiViews
112 </IfModule>
113
114 <IfModule mod_rewrite.c>
115 RewriteEngine On
116
117 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
118 RewriteRule ^(.*) - [E=BASE:%1]
119
120 # Maintenance script
121 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
122 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
123 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
124 ErrorDocument 503 /maintenance.php
125
126 # Sets the HTTP_AUTHORIZATION header removed by Apache
127 RewriteCond %{HTTP:Authorization} .
128 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
129
130 RewriteCond %{ENV:REDIRECT_STATUS} ^$
131 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
132
133 # If the requested filename exists, simply serve it.
134 # We only want to let Apache serve files and not directories.
135 RewriteCond %{REQUEST_FILENAME} -f
136 RewriteRule ^ - [L]
137
138 # Rewrite all other queries to the front controller.
139 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
140 </IfModule>
141
142 </Directory>
143 '' else ''
144 Use Stats connexionswing.com
145
146 <Directory ${root}>
147 Options Indexes FollowSymLinks MultiViews Includes
148 AllowOverride All
149 Require all granted
150 </Directory>
151 ''}
152 '';
153 };
154 activationScript = {
155 deps = [ "wrappers" ];
156 text = ''
157 install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} \
158 ${app.varDir}/medias \
159 ${app.varDir}/uploads \
160 ${app.varDir}/var
161 install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions
162 '';
163 };
164 }