]>
Commit | Line | Data |
---|---|---|
f406130d | 1 | { lib, writeText, fetchedGitPrivate, fetchurl, stdenv, composerEnv }: |
2f0f1c48 | 2 | let |
9d90e7e2 IB |
3 | tellesflorian = { config }: rec { |
4 | environment = config.environment; | |
2f0f1c48 | 5 | varDir = "/var/lib/tellesflorian_${environment}"; |
6e23a06b IB |
6 | keys."${environment}-tellesflorian" = { |
7 | destDir = "/run/keys/webapps"; | |
8 | user = apache.user; | |
9 | group = apache.group; | |
85f5ed68 | 10 | permissions = "0400"; |
6e23a06b | 11 | text = '' |
2f0f1c48 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} | |
2f0f1c48 | 19 | mailer_transport: smtp |
c9af72bc | 20 | mailer_host: 127.0.0.1 |
2f0f1c48 IB |
21 | mailer_user: null |
22 | mailer_password: null | |
9d90e7e2 | 23 | secret: ${config.secret} |
2f0f1c48 | 24 | ''; |
6e23a06b | 25 | }; |
2f0f1c48 | 26 | phpFpm = rec { |
8eded9ec IB |
27 | preStart = '' |
28 | if [ ! -f "${varDir}/currentWebappDir" -o \ | |
29 | ! -f "${varDir}/currentKey" -o \ | |
30 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \ | |
31 | || ! sha512sum -c --status ${varDir}/currentKey; then | |
32 | pushd ${webappDir} > /dev/null | |
33 | /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup | |
34 | popd > /dev/null | |
35 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | |
36 | sha512sum /run/keys/webapps/${environment}-tellesflorian > ${varDir}/currentKey | |
37 | fi | |
38 | ''; | |
a0c845b4 IB |
39 | serviceDeps = [ |
40 | "mysql.service" | |
41 | "${environment}-tellesflorian-passwords-key.service" | |
42 | "${environment}-tellesflorian-key.service" | |
43 | ]; | |
2f0f1c48 IB |
44 | socket = "/var/run/phpfpm/floriantelles-${environment}.sock"; |
45 | pool = '' | |
46 | listen = ${socket} | |
47 | user = ${apache.user} | |
48 | group = ${apache.group} | |
49 | listen.owner = ${apache.user} | |
50 | listen.group = ${apache.group} | |
51 | php_admin_value[upload_max_filesize] = 20M | |
52 | php_admin_value[post_max_size] = 20M | |
53 | ;php_admin_flag[log_errors] = on | |
6e23a06b | 54 | php_admin_value[open_basedir] = "/run/keys/webapps/${environment}-tellesflorian:${webappDir}:${varDir}:/tmp" |
2f0f1c48 IB |
55 | php_admin_value[session.save_path] = "${varDir}/phpSessions" |
56 | ${if environment == "dev" then '' | |
57 | pm = ondemand | |
58 | pm.max_children = 5 | |
59 | pm.process_idle_timeout = 60 | |
60 | env[SYMFONY_DEBUG_MODE] = "yes" | |
61 | '' else '' | |
62 | pm = dynamic | |
63 | pm.max_children = 20 | |
64 | pm.start_servers = 2 | |
65 | pm.min_spare_servers = 1 | |
66 | pm.max_spare_servers = 3 | |
67 | ''}''; | |
68 | }; | |
6e23a06b IB |
69 | keys."${environment}-tellesflorian-passwords" = { |
70 | destDir = "/run/keys/webapps"; | |
71 | user = apache.user; | |
72 | group = apache.group; | |
85f5ed68 | 73 | permissions = "0400"; |
6e23a06b IB |
74 | text = '' |
75 | invite:${config.invite_passwords} | |
2f0f1c48 | 76 | ''; |
6e23a06b | 77 | }; |
e5073add | 78 | apache = rec { |
2f0f1c48 IB |
79 | user = "wwwrun"; |
80 | group = "wwwrun"; | |
81 | modules = [ "proxy_fcgi" ]; | |
e5073add IB |
82 | webappName = "florian_${environment}"; |
83 | root = "/run/current-system/webapps/${webappName}"; | |
2f0f1c48 IB |
84 | vhostConf = '' |
85 | <FilesMatch "\.php$"> | |
86 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
87 | </FilesMatch> | |
88 | ||
89 | ${if environment == "dev" then '' | |
90 | <Location /> | |
91 | AuthBasicProvider file ldap | |
92 | Use LDAPConnect | |
93 | Require ldap-group cn=app.tellesflorian.com,cn=httpd,ou=services,dc=immae,dc=eu | |
94 | ||
6e23a06b | 95 | AuthUserFile "/run/keys/webapps/${environment}-tellesflorian-passwords" |
2f0f1c48 IB |
96 | Require user "invite" |
97 | ||
98 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://tellesflorian.com\"></html>" | |
99 | </Location> | |
100 | ||
e5073add | 101 | <Directory ${root}> |
2f0f1c48 IB |
102 | Options Indexes FollowSymLinks MultiViews Includes |
103 | AllowOverride None | |
104 | Require all granted | |
105 | ||
106 | DirectoryIndex app_dev.php | |
107 | ||
108 | <IfModule mod_negotiation.c> | |
109 | Options -MultiViews | |
110 | </IfModule> | |
111 | ||
112 | <IfModule mod_rewrite.c> | |
113 | RewriteEngine On | |
114 | ||
115 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
116 | RewriteRule ^(.*) - [E=BASE:%1] | |
117 | ||
118 | # Maintenance script | |
119 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | |
120 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | |
121 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | |
122 | ErrorDocument 503 /maintenance.php | |
123 | ||
124 | # Sets the HTTP_AUTHORIZATION header removed by Apache | |
125 | RewriteCond %{HTTP:Authorization} . | |
126 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
127 | ||
128 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | |
129 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | |
130 | ||
131 | # If the requested filename exists, simply serve it. | |
132 | # We only want to let Apache serve files and not directories. | |
133 | RewriteCond %{REQUEST_FILENAME} -f | |
134 | RewriteRule ^ - [L] | |
135 | ||
136 | # Rewrite all other queries to the front controller. | |
137 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | |
138 | </IfModule> | |
139 | ||
140 | </Directory> | |
141 | '' else '' | |
e5073add | 142 | <Directory ${root}> |
2f0f1c48 IB |
143 | Options Indexes FollowSymLinks MultiViews Includes |
144 | AllowOverride All | |
145 | Require all granted | |
146 | </Directory> | |
147 | ''} | |
148 | ''; | |
149 | }; | |
150 | activationScript = { | |
151 | deps = [ "wrappers" ]; | |
152 | text = '' | |
153 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | |
154 | ${varDir}/var | |
155 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | |
2f0f1c48 IB |
156 | ''; |
157 | }; | |
f406130d IB |
158 | webappDir = composerEnv.buildPackage ( |
159 | import ./php-packages.nix { inherit composerEnv fetchurl; } // | |
160 | fetchedGitPrivate ./tellesflorian.json // | |
161 | rec { | |
162 | noDev = (environment == "prod"); | |
163 | preInstall = '' | |
164 | export SYMFONY_ENV="${environment}" | |
165 | ''; | |
166 | postInstall = '' | |
167 | cd $out | |
168 | rm app/config/parameters.yml | |
6e23a06b | 169 | ln -sf /run/keys/webapps/${environment}-tellesflorian app/config/parameters.yml |
f406130d | 170 | rm -rf var/{logs,cache} |
3c8d7f87 | 171 | ln -sf ${varDir}/var/{logs,cache,sessions} var/ |
f406130d IB |
172 | ''; |
173 | }); | |
2f0f1c48 IB |
174 | webRoot = "${webappDir}/web"; |
175 | }; | |
176 | in | |
177 | tellesflorian |