]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/modules/websites/piedsjaloux/piedsjaloux.nix
Purify Florian's website
[perso/Immae/Config/Nix.git] / virtual / modules / websites / piedsjaloux / piedsjaloux.nix
CommitLineData
9d90e7e2 1{ lib, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages, texlive, imagemagick }:
34e2fd14 2let
9d90e7e2
IB
3 piedsjaloux = { config }: rec {
4 environment = config.environment;
34e2fd14 5 varDir = "/var/lib/piedsjaloux_${environment}";
34e2fd14 6 configRoot =
34e2fd14
IB
7 writeText "parameters.yml" ''
8 # This file is auto-generated during the composer install
9 parameters:
10 database_host: db-1.immae.eu
11 database_port: null
9d90e7e2
IB
12 database_name: ${config.mysql.name}
13 database_user: ${config.mysql.user}
14 database_password: ${config.mysql.password}
34e2fd14
IB
15 mailer_transport: smtp
16 mailer_host: mail.immae.eu
17 mailer_user: null
18 mailer_password: null
9d90e7e2 19 secret: ${config.secret}
34e2fd14
IB
20 pdflatex: "${texlive.combine { inherit (texlive) attachfile preprint scheme-small; }}/bin/pdflatex"
21 leapt_im:
22 binary_path: ${imagemagick}/bin
23 '';
24 phpFpm = rec {
25 socket = "/var/run/phpfpm/piedsjaloux-${environment}.sock";
26 pool = ''
27 listen = ${socket}
28 user = ${apache.user}
29 group = ${apache.group}
30 listen.owner = ${apache.user}
31 listen.group = ${apache.group}
32 php_admin_value[upload_max_filesize] = 20M
33 php_admin_value[post_max_size] = 20M
34 ;php_admin_flag[log_errors] = on
35 php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp"
c8e019b6 36 php_admin_value[session.save_path] = "${varDir}/phpSessions"
34e2fd14
IB
37 ${if environment == "dev" then ''
38 pm = ondemand
39 pm.max_children = 5
40 pm.process_idle_timeout = 60
41 env[SYMFONY_DEBUG_MODE] = "yes"
42 '' else ''
43 pm = dynamic
44 pm.max_children = 20
45 pm.start_servers = 2
46 pm.min_spare_servers = 1
47 pm.max_spare_servers = 3
48 ''}'';
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 Use LDAPConnect
62 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
63 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>"
64 </Location>
65
66 <Directory ${webRoot}>
67 Options Indexes FollowSymLinks MultiViews Includes
68 AllowOverride None
69 Require all granted
70
71 DirectoryIndex app_dev.php
72
73 <IfModule mod_negotiation.c>
74 Options -MultiViews
75 </IfModule>
76
77 <IfModule mod_rewrite.c>
78 RewriteEngine On
79
80 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
81 RewriteRule ^(.*) - [E=BASE:%1]
82
83 # Maintenance script
84 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
85 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
86 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
87 ErrorDocument 503 /maintenance.php
88
89 # Sets the HTTP_AUTHORIZATION header removed by Apache
90 RewriteCond %{HTTP:Authorization} .
91 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
92
93 RewriteCond %{ENV:REDIRECT_STATUS} ^$
94 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
95
96 # If the requested filename exists, simply serve it.
97 # We only want to let Apache serve files and not directories.
98 RewriteCond %{REQUEST_FILENAME} -f
99 RewriteRule ^ - [L]
100
101 # Rewrite all other queries to the front controller.
102 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
103 </IfModule>
104
105 </Directory>
106 '' else ''
107 Use Stats piedsjaloux.fr
108
109 <Directory ${webRoot}>
110 Options Indexes FollowSymLinks MultiViews Includes
111 AllowOverride All
112 Require all granted
113 </Directory>
114 ''}
115 '';
116 };
117 activationScript = {
118 deps = [ "wrappers" ];
119 text = ''
120 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
121 ${varDir}/tmp
c8e019b6 122 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
34e2fd14
IB
123 if [ ! -f "${varDir}/currentWebappDir" -o \
124 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
125 pushd ${webappDir} > /dev/null
126 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
127 popd > /dev/null
128 echo -n "${webappDir}" > ${varDir}/currentWebappDir
129 fi
130 '';
131 };
132 webappDir = stdenv.mkDerivation (fetchedGitPrivate ./piedsjaloux.json // rec {
a5365ec3
IB
133 # /!\ miniatures and data need to be in the same dir due to a
134 # bug in leapt.im (searches for data/../miniatures)
34e2fd14
IB
135 buildPhase = ''
136 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
137 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
138
139 ln -sf ${configRoot} app/config/parameters.yml
140 sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json
141 ${if environment == "dev" then ''
142 composer install
143 '' else ''
144 SYMFONY_ENV=prod composer install --no-dev
145 ''}
146 rm -rf var
147 ln -sf ../../../../../${varDir} var
148 '';
149 installPhase = ''
150 cp -a . $out
151 '';
152 buildInputs = [
153 php git cacert phpPackages.composer
154 ];
155 });
156 webRoot = "${webappDir}/web";
157 };
158in
159 piedsjaloux