]>
Commit | Line | Data |
---|---|---|
1 | { pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, 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: db-1.immae.eu | |
11 | database_port: null | |
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: smtp | |
17 | mailer_host: mail.immae.eu | |
18 | mailer_user: null | |
19 | mailer_password: null | |
20 | subscription_email: ${config.email} | |
21 | allow_robots: true | |
22 | secret: ${config.secret} | |
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" | |
36 | php_admin_value[session.save_path] = "${varDir}/phpSessions" | |
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> | |
118 | '' else '' | |
119 | Use Stats connexionswing.com | |
120 | ||
121 | <Directory ${webRoot}> | |
122 | Options Indexes FollowSymLinks MultiViews Includes | |
123 | AllowOverride All | |
124 | Require all granted | |
125 | </Directory> | |
126 | ''} | |
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 | |
136 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | |
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 | }; | |
146 | webappDir = composerEnv.buildPackage ( | |
147 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | |
148 | fetchedGitPrivate ./connexionswing.json // | |
149 | rec { | |
150 | noDev = (environment == "prod"); | |
151 | preInstall = '' | |
152 | export SYMFONY_ENV="${environment}" | |
153 | ''; | |
154 | postInstall = '' | |
155 | cd $out | |
156 | ${if environment == "prod" then "php ./bin/console assetic:dump --env=prod --no-debug" else ""} | |
157 | rm app/config/parameters.yml | |
158 | ln -sf ${configRoot} app/config/parameters.yml | |
159 | rm -rf var/{logs,cache} | |
160 | ln -sf ../../../../../../${varDir}/var/{logs,cache} var/ | |
161 | ln -sf ../../../../../${varDir}/{medias,uploads} web/images/ | |
162 | ''; | |
163 | }); | |
164 | webRoot = "${webappDir}/web"; | |
165 | }; | |
166 | in | |
167 | connexionswing |