]>
Commit | Line | Data |
---|---|---|
34e2fd14 IB |
1 | { lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages, texlive, imagemagick }: |
2 | let | |
3 | piedsjaloux = { environment ? "dev" }: rec { | |
4 | varPrefix = "PIEDSJALOUX"; | |
5 | varDir = "/var/lib/piedsjaloux_${environment}"; | |
6 | envName= lib.strings.toUpper environment; | |
7 | configRoot = | |
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 | pdflatex: "${texlive.combine { inherit (texlive) attachfile preprint scheme-small; }}/bin/pdflatex" | |
26 | leapt_im: | |
27 | binary_path: ${imagemagick}/bin | |
28 | ''; | |
29 | phpFpm = rec { | |
30 | socket = "/var/run/phpfpm/piedsjaloux-${environment}.sock"; | |
31 | pool = '' | |
32 | listen = ${socket} | |
33 | user = ${apache.user} | |
34 | group = ${apache.group} | |
35 | listen.owner = ${apache.user} | |
36 | listen.group = ${apache.group} | |
37 | php_admin_value[upload_max_filesize] = 20M | |
38 | php_admin_value[post_max_size] = 20M | |
39 | ;php_admin_flag[log_errors] = on | |
40 | php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" | |
41 | ${if environment == "dev" then '' | |
42 | pm = ondemand | |
43 | pm.max_children = 5 | |
44 | pm.process_idle_timeout = 60 | |
45 | env[SYMFONY_DEBUG_MODE] = "yes" | |
46 | '' else '' | |
47 | pm = dynamic | |
48 | pm.max_children = 20 | |
49 | pm.start_servers = 2 | |
50 | pm.min_spare_servers = 1 | |
51 | pm.max_spare_servers = 3 | |
52 | ''}''; | |
53 | }; | |
54 | apache = { | |
55 | user = "wwwrun"; | |
56 | group = "wwwrun"; | |
57 | modules = [ "proxy_fcgi" ]; | |
58 | vhostConf = '' | |
59 | <FilesMatch "\.php$"> | |
60 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
61 | </FilesMatch> | |
62 | ||
63 | ${if environment == "dev" then '' | |
64 | <Location /> | |
65 | Use LDAPConnect | |
66 | Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | |
67 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>" | |
68 | </Location> | |
69 | ||
70 | <Directory ${webRoot}> | |
71 | Options Indexes FollowSymLinks MultiViews Includes | |
72 | AllowOverride None | |
73 | Require all granted | |
74 | ||
75 | DirectoryIndex app_dev.php | |
76 | ||
77 | <IfModule mod_negotiation.c> | |
78 | Options -MultiViews | |
79 | </IfModule> | |
80 | ||
81 | <IfModule mod_rewrite.c> | |
82 | RewriteEngine On | |
83 | ||
84 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
85 | RewriteRule ^(.*) - [E=BASE:%1] | |
86 | ||
87 | # Maintenance script | |
88 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | |
89 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | |
90 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | |
91 | ErrorDocument 503 /maintenance.php | |
92 | ||
93 | # Sets the HTTP_AUTHORIZATION header removed by Apache | |
94 | RewriteCond %{HTTP:Authorization} . | |
95 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
96 | ||
97 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | |
98 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | |
99 | ||
100 | # If the requested filename exists, simply serve it. | |
101 | # We only want to let Apache serve files and not directories. | |
102 | RewriteCond %{REQUEST_FILENAME} -f | |
103 | RewriteRule ^ - [L] | |
104 | ||
105 | # Rewrite all other queries to the front controller. | |
106 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | |
107 | </IfModule> | |
108 | ||
109 | </Directory> | |
110 | '' else '' | |
111 | Use Stats piedsjaloux.fr | |
112 | ||
113 | <Directory ${webRoot}> | |
114 | Options Indexes FollowSymLinks MultiViews Includes | |
115 | AllowOverride All | |
116 | Require all granted | |
117 | </Directory> | |
118 | ''} | |
119 | ''; | |
120 | }; | |
121 | activationScript = { | |
122 | deps = [ "wrappers" ]; | |
123 | text = '' | |
124 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | |
125 | ${varDir}/tmp | |
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 | }; | |
135 | webappDir = stdenv.mkDerivation (fetchedGitPrivate ./piedsjaloux.json // rec { | |
136 | # FIXME: can we do better than symlink? | |
137 | # FIXME: initial sync | |
138 | # FIXME: backup | |
139 | # FIXME: miniatures and data need to be in the same dir due to a | |
140 | # bug in leapt.im (searches for data/../miniatures) | |
141 | # FIXME: var/bootstrap.php.cache doesn't get created | |
142 | # (cannot work with var as a symlink since the file | |
143 | # references ..) | |
144 | # FIXME: configuration change should not trigger a rebuild | |
145 | buildPhase = '' | |
146 | export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt | |
147 | export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt | |
148 | ||
149 | ln -sf ${configRoot} app/config/parameters.yml | |
150 | sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json | |
151 | ${if environment == "dev" then '' | |
152 | composer install | |
153 | '' else '' | |
154 | SYMFONY_ENV=prod composer install --no-dev | |
155 | ''} | |
156 | rm -rf var | |
157 | ln -sf ../../../../../${varDir} var | |
158 | ''; | |
159 | installPhase = '' | |
160 | cp -a . $out | |
161 | ''; | |
162 | buildInputs = [ | |
163 | php git cacert phpPackages.composer | |
164 | ]; | |
165 | }); | |
166 | webRoot = "${webappDir}/web"; | |
167 | }; | |
168 | in | |
169 | piedsjaloux |