]>
Commit | Line | Data |
---|---|---|
2f0f1c48 IB |
1 | { lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages }: |
2 | let | |
3 | tellesflorian = { environment ? "dev" }: rec { | |
4 | varPrefix = "TELLESFLORIAN"; | |
5 | varDir = "/var/lib/tellesflorian_${environment}"; | |
6 | envName= lib.strings.toUpper environment; | |
7 | configRoot = | |
2f0f1c48 IB |
8 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD"; |
9 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER"; | |
10 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_NAME"; | |
11 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_SECRET"; | |
12 | writeText "parameters.yml" '' | |
13 | # This file is auto-generated during the composer install | |
14 | parameters: | |
15 | database_host: db-1.immae.eu | |
16 | database_port: null | |
17 | database_name: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_NAME"} | |
18 | database_user: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER"} | |
19 | database_password: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD"} | |
20 | mailer_transport: smtp | |
21 | mailer_host: mail.immae.eu | |
22 | mailer_user: null | |
23 | mailer_password: null | |
24 | secret: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"} | |
25 | ''; | |
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 | |
37 | php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" | |
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 | }; | |
52 | passwords = | |
53 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_INVITE_PASSWORDS"; | |
54 | writeText "tellesflorian_passwords" '' | |
55 | invite:${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_INVITE_PASSWORDS"} | |
56 | ''; | |
57 | apache = { | |
58 | user = "wwwrun"; | |
59 | group = "wwwrun"; | |
60 | modules = [ "proxy_fcgi" ]; | |
61 | vhostConf = '' | |
62 | <FilesMatch "\.php$"> | |
63 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
64 | </FilesMatch> | |
65 | ||
66 | ${if environment == "dev" then '' | |
67 | <Location /> | |
68 | AuthBasicProvider file ldap | |
69 | Use LDAPConnect | |
70 | Require ldap-group cn=app.tellesflorian.com,cn=httpd,ou=services,dc=immae,dc=eu | |
71 | ||
72 | AuthUserFile "${passwords}" | |
73 | Require user "invite" | |
74 | ||
75 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://tellesflorian.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 | <Directory ${webRoot}> | |
120 | Options Indexes FollowSymLinks MultiViews Includes | |
121 | AllowOverride All | |
122 | Require all granted | |
123 | </Directory> | |
124 | ''} | |
125 | ''; | |
126 | }; | |
127 | activationScript = { | |
128 | deps = [ "wrappers" ]; | |
129 | text = '' | |
130 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | |
131 | ${varDir}/var | |
132 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | |
133 | if [ ! -f "${varDir}/currentWebappDir" -o \ | |
134 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | |
135 | pushd ${webappDir} > /dev/null | |
136 | $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup | |
137 | popd > /dev/null | |
138 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | |
139 | fi | |
140 | ''; | |
141 | }; | |
142 | webappDir = stdenv.mkDerivation (fetchedGitPrivate ./tellesflorian.json // rec { | |
2f0f1c48 IB |
143 | buildPhase = '' |
144 | export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt | |
145 | export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt | |
146 | ||
147 | ln -sf ${configRoot} app/config/parameters.yml | |
148 | sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json | |
149 | ${if environment == "dev" then '' | |
150 | composer install | |
151 | '' else '' | |
152 | SYMFONY_ENV=prod composer install --no-dev | |
153 | ''} | |
154 | rm -rf var | |
155 | ln -sf ../../../../../${varDir}/var var | |
156 | ''; | |
157 | installPhase = '' | |
158 | cp -a . $out | |
159 | ''; | |
160 | buildInputs = [ | |
161 | php git cacert phpPackages.composer | |
162 | ]; | |
163 | }); | |
164 | webRoot = "${webappDir}/web"; | |
165 | }; | |
166 | in | |
167 | tellesflorian |