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