]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - nixops/modules/websites/piedsjaloux/piedsjaloux.nix
Remove direct dependency to myconfig in database modules
[perso/Immae/Config/Nix.git] / nixops / modules / websites / piedsjaloux / piedsjaloux.nix
1 { piedsjaloux, config, pkgs, lib, texlive, imagemagick }:
2 rec {
3 app = piedsjaloux.override { inherit (config) environment; };
4 varDir = "/var/lib/piedsjaloux_${app.environment}";
5 keys = [{
6 dest = "webapps/${app.environment}-piedsjaloux";
7 user = apache.user;
8 group = apache.group;
9 permissions = "0400";
10 text = ''
11 # This file is auto-generated during the composer install
12 parameters:
13 database_host: ${config.mysql.host}
14 database_port: ${config.mysql.port}
15 database_name: ${config.mysql.name}
16 database_user: ${config.mysql.user}
17 database_password: ${config.mysql.password}
18 database_server_version: ${pkgs.mariadb.mysqlVersion}
19 mailer_transport: smtp
20 mailer_host: 127.0.0.1
21 mailer_user: null
22 mailer_password: null
23 secret: ${config.secret}
24 pdflatex: "${texlive.combine { inherit (texlive) attachfile preprint scheme-small; }}/bin/pdflatex"
25 leapt_im:
26 binary_path: ${imagemagick}/bin
27 '';
28 }];
29 phpFpm = rec {
30 preStart = ''
31 if [ ! -f "${app.varDir}/currentWebappDir" -o \
32 ! -f "${app.varDir}/currentKey" -o \
33 "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
34 || ! sha512sum -c --status ${app.varDir}/currentKey; then
35 pushd ${app} > /dev/null
36 /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${app.environment} cache:clear --no-warmup
37 popd > /dev/null
38 echo -n "${app}" > ${app.varDir}/currentWebappDir
39 sha512sum /var/secrets/webapps/${app.environment}-piedsjaloux > ${app.varDir}/currentKey
40 fi
41 '';
42 serviceDeps = [ "mysql.service" ];
43 socket = "/var/run/phpfpm/piedsjaloux-${app.environment}.sock";
44 pool = ''
45 listen = ${socket}
46 user = ${apache.user}
47 group = ${apache.group}
48 listen.owner = ${apache.user}
49 listen.group = ${apache.group}
50 php_admin_value[upload_max_filesize] = 20M
51 php_admin_value[post_max_size] = 20M
52 ;php_admin_flag[log_errors] = on
53 php_admin_value[open_basedir] = "/var/secrets/webapps/${app.environment}-piedsjaloux:${app}:${app.varDir}:/tmp"
54 php_admin_value[session.save_path] = "${app.varDir}/phpSessions"
55 env[PATH] = ${lib.makeBinPath [ pkgs.apg pkgs.unzip ]}
56 ${if app.environment == "dev" then ''
57 pm = ondemand
58 pm.max_children = 5
59 pm.process_idle_timeout = 60
60 env[SYMFONY_DEBUG_MODE] = "yes"
61 '' else ''
62 pm = dynamic
63 pm.max_children = 20
64 pm.start_servers = 2
65 pm.min_spare_servers = 1
66 pm.max_spare_servers = 3
67 ''}'';
68 };
69 apache = rec {
70 user = "wwwrun";
71 group = "wwwrun";
72 modules = [ "proxy_fcgi" ];
73 webappName = "piedsjaloux_${app.environment}";
74 root = "/run/current-system/webapps/${webappName}";
75 vhostConf = ''
76 <FilesMatch "\.php$">
77 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
78 </FilesMatch>
79
80 ${if app.environment == "dev" then ''
81 <Location />
82 Use LDAPConnect
83 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
84 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>"
85 </Location>
86
87 <Directory ${root}>
88 Options Indexes FollowSymLinks MultiViews Includes
89 AllowOverride None
90 Require all granted
91
92 DirectoryIndex app_dev.php
93
94 <IfModule mod_negotiation.c>
95 Options -MultiViews
96 </IfModule>
97
98 <IfModule mod_rewrite.c>
99 RewriteEngine On
100
101 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
102 RewriteRule ^(.*) - [E=BASE:%1]
103
104 # Maintenance script
105 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
106 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
107 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
108 ErrorDocument 503 /maintenance.php
109
110 # Sets the HTTP_AUTHORIZATION header removed by Apache
111 RewriteCond %{HTTP:Authorization} .
112 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
113
114 RewriteCond %{ENV:REDIRECT_STATUS} ^$
115 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
116
117 # If the requested filename exists, simply serve it.
118 # We only want to let Apache serve files and not directories.
119 RewriteCond %{REQUEST_FILENAME} -f
120 RewriteRule ^ - [L]
121
122 # Rewrite all other queries to the front controller.
123 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
124 </IfModule>
125
126 </Directory>
127 '' else ''
128 Use Stats piedsjaloux.fr
129
130 <Directory ${root}>
131 Options Indexes FollowSymLinks MultiViews Includes
132 AllowOverride All
133 Require all granted
134 </Directory>
135 ''}
136 '';
137 };
138 activationScript = {
139 deps = [ "wrappers" ];
140 text = ''
141 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${app.varDir} \
142 ${app.varDir}/tmp
143 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${app.varDir}/phpSessions
144 '';
145 };
146 }