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