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