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