1 { lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert }:
3 connexionswing = { environment ? "dev" }: rec {
4 varDir = "/var/lib/connexionswing_${environment}";
5 envName= lib.strings.toUpper environment;
7 # FIXME: spool emails in prod for when immae.eu is down?
8 assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_PASSWORD";
9 assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_USER";
10 assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_NAME";
11 assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_SECRET";
12 assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_EMAIL";
13 writeText "parameters.yml" ''
14 # This file is auto-generated during the composer install
16 database_host: db-1.immae.eu
18 database_name: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_NAME"}
19 database_user: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_USER"}
20 database_password: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_PASSWORD"}
21 mailer_transport: smtp
22 mailer_host: mail.immae.eu
25 subscription_email: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_EMAIL"}
27 secret: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_SECRET"}
30 socket = "/var/run/phpfpm/connexionswing-${environment}.sock";
34 group = ${apache.group}
35 listen.owner = ${apache.user}
36 listen.group = ${apache.group}
37 php_admin_value[upload_max_filesize] = 20M
38 php_admin_value[post_max_size] = 20M
39 ;php_admin_flag[log_errors] = on
40 php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp"
41 php_admin_value[session.save_path] = "${varDir}/phpSessions"
42 ${if environment == "dev" then ''
45 pm.process_idle_timeout = 60
46 env[SYMFONY_DEBUG_MODE] = "yes"
51 pm.min_spare_servers = 1
52 pm.max_spare_servers = 3
58 modules = [ "proxy_fcgi" ];
61 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
64 <Directory ${varDir}/medias>
65 Options FollowSymLinks
70 <Directory ${varDir}/uploads>
71 Options FollowSymLinks
76 ${if environment == "dev" then ''
79 Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
80 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>"
83 <Directory ${webRoot}>
84 Options Indexes FollowSymLinks MultiViews Includes
88 DirectoryIndex app_dev.php
90 <IfModule mod_negotiation.c>
94 <IfModule mod_rewrite.c>
97 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
98 RewriteRule ^(.*) - [E=BASE:%1]
101 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
102 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
103 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
104 ErrorDocument 503 /maintenance.php
106 # Sets the HTTP_AUTHORIZATION header removed by Apache
107 RewriteCond %{HTTP:Authorization} .
108 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
110 RewriteCond %{ENV:REDIRECT_STATUS} ^$
111 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
113 # If the requested filename exists, simply serve it.
114 # We only want to let Apache serve files and not directories.
115 RewriteCond %{REQUEST_FILENAME} -f
118 # Rewrite all other queries to the front controller.
119 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
124 <Directory ${webRoot}>
125 Options Indexes FollowSymLinks MultiViews Includes
133 deps = [ "wrappers" ];
135 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
139 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
140 if [ ! -f "${varDir}/currentWebappDir" -o \
141 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
142 pushd ${webappDir} > /dev/null
143 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
145 echo -n "${webappDir}" > ${varDir}/currentWebappDir
149 webappDir = stdenv.mkDerivation (fetchedGitPrivate ./connexionswing_master.json // rec {
150 # FIXME: can we do better than symlink?
151 # FIXME: imagick optional
152 # FIXME: initial sync
154 # FIXME: replace with pkgs.phpPackages.composer
156 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
157 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
159 ln -sf ../../../../../${varDir}/{medias,uploads} web/images/
160 ln -sf ${configRoot} app/config/parameters.yml
161 ${if environment == "dev" then "php bin/composer install" else ''
162 SYMFONY_ENV=prod php bin/composer install --no-dev
163 ./bin/console assetic:dump --env=prod --no-debug
166 ln -sf ../../../../../${varDir}/var var
175 webRoot = "${webappDir}/web";