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