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