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