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