1 { pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, phpPackages, fetchurl, fetchgit }:
3 connexionswing = { config }: rec {
4 environment = config.environment;
5 varDir = "/var/lib/connexionswing_${environment}";
6 keys."${environment}-connexionswing" = {
7 destDir = "/run/keys/webapps";
12 # This file is auto-generated during the composer install
14 database_host: ${config.mysql.host}
15 database_port: ${config.mysql.port}
16 database_name: ${config.mysql.name}
17 database_user: ${config.mysql.user}
18 database_password: ${config.mysql.password}
19 database_server_version: ${pkgs.mariadb.mysqlVersion}
20 mailer_transport: sendmail
24 subscription_email: ${config.email}
26 secret: ${config.secret}
27 ${if environment == "prod" then ''
29 swiftmailer.mailer.default.transport:
30 class: Swift_SendmailTransport
31 arguments: ['/run/wrappers/bin/sendmail -bs']
36 serviceDeps = [ "mysql.service" "${environment}-connexionswing-key.service" ];
37 socket = "/var/run/phpfpm/connexionswing-${environment}.sock";
39 extension=${phpPackages.imagick}/lib/php/extensions/imagick.so
44 group = ${apache.group}
45 listen.owner = ${apache.user}
46 listen.group = ${apache.group}
47 php_admin_value[upload_max_filesize] = 20M
48 php_admin_value[post_max_size] = 20M
49 ;php_admin_flag[log_errors] = on
50 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/run/keys/webapps/${environment}-connexionswing:${webappDir}:${varDir}:/tmp"
51 php_admin_value[session.save_path] = "${varDir}/phpSessions"
52 ${if environment == "dev" then ''
55 pm.process_idle_timeout = 60
56 env[SYMFONY_DEBUG_MODE] = "yes"
61 pm.min_spare_servers = 1
62 pm.max_spare_servers = 3
68 modules = [ "proxy_fcgi" ];
69 webappName = "connexionswing_${environment}";
70 root = "/run/current-system/webapps/${webappName}";
73 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
76 <Directory ${varDir}/medias>
77 Options FollowSymLinks
82 <Directory ${varDir}/uploads>
83 Options FollowSymLinks
88 ${if environment == "dev" then ''
91 Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
92 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>"
96 Options Indexes FollowSymLinks MultiViews Includes
100 DirectoryIndex app_dev.php
102 <IfModule mod_negotiation.c>
106 <IfModule mod_rewrite.c>
109 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
110 RewriteRule ^(.*) - [E=BASE:%1]
113 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
114 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
115 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
116 ErrorDocument 503 /maintenance.php
118 # Sets the HTTP_AUTHORIZATION header removed by Apache
119 RewriteCond %{HTTP:Authorization} .
120 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
122 RewriteCond %{ENV:REDIRECT_STATUS} ^$
123 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
125 # If the requested filename exists, simply serve it.
126 # We only want to let Apache serve files and not directories.
127 RewriteCond %{REQUEST_FILENAME} -f
130 # Rewrite all other queries to the front controller.
131 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
136 Use Stats connexionswing.com
139 Options Indexes FollowSymLinks MultiViews Includes
147 deps = [ "wrappers" ];
149 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
153 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
154 if [ ! -f "${varDir}/currentWebappDir" -o \
155 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
156 pushd ${webappDir} > /dev/null
157 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
159 echo -n "${webappDir}" > ${varDir}/currentWebappDir
163 webappDir = composerEnv.buildPackage (
164 import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } //
165 fetchedGitPrivate ./connexionswing.json //
167 noDev = (environment == "prod");
169 export SYMFONY_ENV="${environment}"
173 ${if environment == "prod" then "php ./bin/console assetic:dump --env=prod --no-debug" else ""}
174 rm app/config/parameters.yml
175 ln -sf /run/keys/webapps/${environment}-connexionswing app/config/parameters.yml
176 rm -rf var/{logs,cache}
177 ln -sf ${varDir}/var/{logs,cache} var/
178 ln -sf ${varDir}/{medias,uploads} web/images/
181 webRoot = "${webappDir}/web";