]>
Commit | Line | Data |
---|---|---|
2abb172b | 1 | { pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, phpPackages, fetchurl, fetchgit }: |
940f1834 | 2 | let |
9d90e7e2 IB |
3 | connexionswing = { config }: rec { |
4 | environment = config.environment; | |
940f1834 | 5 | varDir = "/var/lib/connexionswing_${environment}"; |
940f1834 | 6 | configRoot = |
5c101474 | 7 | writeText "parameters.yml" '' |
940f1834 IB |
8 | # This file is auto-generated during the composer install |
9 | parameters: | |
10 | database_host: db-1.immae.eu | |
11 | database_port: null | |
9d90e7e2 IB |
12 | database_name: ${config.mysql.name} |
13 | database_user: ${config.mysql.user} | |
14 | database_password: ${config.mysql.password} | |
d78128ec | 15 | database_server_version: ${pkgs.mariadb.mysqlVersion} |
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"; | |
2abb172b IB |
26 | phpConfig = '' |
27 | extension=${phpPackages.imagick}/lib/php/extensions/imagick.so | |
28 | ''; | |
940f1834 IB |
29 | pool = '' |
30 | listen = ${socket} | |
31 | user = ${apache.user} | |
32 | group = ${apache.group} | |
33 | listen.owner = ${apache.user} | |
34 | listen.group = ${apache.group} | |
35 | php_admin_value[upload_max_filesize] = 20M | |
36 | php_admin_value[post_max_size] = 20M | |
37 | ;php_admin_flag[log_errors] = on | |
38 | php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" | |
c8e019b6 | 39 | php_admin_value[session.save_path] = "${varDir}/phpSessions" |
940f1834 IB |
40 | ${if environment == "dev" then '' |
41 | pm = ondemand | |
42 | pm.max_children = 5 | |
43 | pm.process_idle_timeout = 60 | |
44 | env[SYMFONY_DEBUG_MODE] = "yes" | |
45 | '' else '' | |
46 | pm = dynamic | |
47 | pm.max_children = 20 | |
48 | pm.start_servers = 2 | |
49 | pm.min_spare_servers = 1 | |
50 | pm.max_spare_servers = 3 | |
51 | ''}''; | |
52 | }; | |
53 | apache = { | |
54 | user = "wwwrun"; | |
55 | group = "wwwrun"; | |
56 | modules = [ "proxy_fcgi" ]; | |
57 | vhostConf = '' | |
58 | <FilesMatch "\.php$"> | |
59 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
60 | </FilesMatch> | |
61 | ||
62 | <Directory ${varDir}/medias> | |
63 | Options FollowSymLinks | |
64 | AllowOverride None | |
65 | Require all granted | |
66 | </Directory> | |
67 | ||
68 | <Directory ${varDir}/uploads> | |
69 | Options FollowSymLinks | |
70 | AllowOverride None | |
71 | Require all granted | |
72 | </Directory> | |
73 | ||
74 | ${if environment == "dev" then '' | |
75 | <Location /> | |
76 | Use LDAPConnect | |
77 | Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | |
78 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>" | |
79 | </Location> | |
80 | ||
81 | <Directory ${webRoot}> | |
82 | Options Indexes FollowSymLinks MultiViews Includes | |
83 | AllowOverride None | |
84 | Require all granted | |
85 | ||
86 | DirectoryIndex app_dev.php | |
87 | ||
88 | <IfModule mod_negotiation.c> | |
89 | Options -MultiViews | |
90 | </IfModule> | |
91 | ||
92 | <IfModule mod_rewrite.c> | |
93 | RewriteEngine On | |
94 | ||
95 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
96 | RewriteRule ^(.*) - [E=BASE:%1] | |
97 | ||
98 | # Maintenance script | |
99 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | |
100 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | |
101 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | |
102 | ErrorDocument 503 /maintenance.php | |
103 | ||
104 | # Sets the HTTP_AUTHORIZATION header removed by Apache | |
105 | RewriteCond %{HTTP:Authorization} . | |
106 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
107 | ||
108 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | |
109 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | |
110 | ||
111 | # If the requested filename exists, simply serve it. | |
112 | # We only want to let Apache serve files and not directories. | |
113 | RewriteCond %{REQUEST_FILENAME} -f | |
114 | RewriteRule ^ - [L] | |
115 | ||
116 | # Rewrite all other queries to the front controller. | |
117 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | |
118 | </IfModule> | |
119 | ||
120 | </Directory> | |
e42ba74f | 121 | '' else '' |
527e32ad IB |
122 | Use Stats connexionswing.com |
123 | ||
e42ba74f IB |
124 | <Directory ${webRoot}> |
125 | Options Indexes FollowSymLinks MultiViews Includes | |
126 | AllowOverride All | |
127 | Require all granted | |
128 | </Directory> | |
129 | ''} | |
940f1834 IB |
130 | ''; |
131 | }; | |
132 | activationScript = { | |
133 | deps = [ "wrappers" ]; | |
134 | text = '' | |
135 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | |
136 | ${varDir}/medias \ | |
137 | ${varDir}/uploads \ | |
138 | ${varDir}/var | |
c8e019b6 | 139 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions |
940f1834 IB |
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 | |
144 | popd > /dev/null | |
145 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | |
146 | fi | |
147 | ''; | |
148 | }; | |
d78128ec IB |
149 | webappDir = composerEnv.buildPackage ( |
150 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | |
151 | fetchedGitPrivate ./connexionswing.json // | |
152 | rec { | |
153 | noDev = (environment == "prod"); | |
154 | preInstall = '' | |
155 | export SYMFONY_ENV="${environment}" | |
156 | ''; | |
157 | postInstall = '' | |
158 | cd $out | |
159 | ${if environment == "prod" then "php ./bin/console assetic:dump --env=prod --no-debug" else ""} | |
160 | rm app/config/parameters.yml | |
161 | ln -sf ${configRoot} app/config/parameters.yml | |
162 | rm -rf var/{logs,cache} | |
163 | ln -sf ../../../../../../${varDir}/var/{logs,cache} var/ | |
164 | ln -sf ../../../../../${varDir}/{medias,uploads} web/images/ | |
165 | ''; | |
166 | }); | |
940f1834 IB |
167 | webRoot = "${webappDir}/web"; |
168 | }; | |
5c101474 | 169 | in |
940f1834 | 170 | connexionswing |