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