]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/modules/websites/piedsjaloux/piedsjaloux.nix
Fix deprecation for networking addresses in hetzner
[perso/Immae/Config/Nix.git] / virtual / modules / websites / piedsjaloux / piedsjaloux.nix
CommitLineData
34e2fd14
IB
1{ lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages, texlive, imagemagick }:
2let
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"
c8e019b6 41 php_admin_value[session.save_path] = "${varDir}/phpSessions"
34e2fd14
IB
42 ${if environment == "dev" then ''
43 pm = ondemand
44 pm.max_children = 5
45 pm.process_idle_timeout = 60
46 env[SYMFONY_DEBUG_MODE] = "yes"
47 '' else ''
48 pm = dynamic
49 pm.max_children = 20
50 pm.start_servers = 2
51 pm.min_spare_servers = 1
52 pm.max_spare_servers = 3
53 ''}'';
54 };
55 apache = {
56 user = "wwwrun";
57 group = "wwwrun";
58 modules = [ "proxy_fcgi" ];
59 vhostConf = ''
60 <FilesMatch "\.php$">
61 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
62 </FilesMatch>
63
64 ${if environment == "dev" then ''
65 <Location />
66 Use LDAPConnect
67 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
68 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></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 Use Stats piedsjaloux.fr
113
114 <Directory ${webRoot}>
115 Options Indexes FollowSymLinks MultiViews Includes
116 AllowOverride All
117 Require all granted
118 </Directory>
119 ''}
120 '';
121 };
122 activationScript = {
123 deps = [ "wrappers" ];
124 text = ''
125 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
126 ${varDir}/tmp
c8e019b6 127 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
34e2fd14
IB
128 if [ ! -f "${varDir}/currentWebappDir" -o \
129 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
130 pushd ${webappDir} > /dev/null
131 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
132 popd > /dev/null
133 echo -n "${webappDir}" > ${varDir}/currentWebappDir
134 fi
135 '';
136 };
137 webappDir = stdenv.mkDerivation (fetchedGitPrivate ./piedsjaloux.json // rec {
a5365ec3
IB
138 # /!\ miniatures and data need to be in the same dir due to a
139 # bug in leapt.im (searches for data/../miniatures)
34e2fd14
IB
140 buildPhase = ''
141 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
142 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
143
144 ln -sf ${configRoot} app/config/parameters.yml
145 sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json
146 ${if environment == "dev" then ''
147 composer install
148 '' else ''
149 SYMFONY_ENV=prod composer install --no-dev
150 ''}
151 rm -rf var
152 ln -sf ../../../../../${varDir} var
153 '';
154 installPhase = ''
155 cp -a . $out
156 '';
157 buildInputs = [
158 php git cacert phpPackages.composer
159 ];
160 });
161 webRoot = "${webappDir}/web";
162 };
163in
164 piedsjaloux