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