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