]>
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}"; |
6e23a06b IB |
6 | keys."${environment}-piedsjaloux" = { |
7 | destDir = "/run/keys/webapps"; | |
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 | ''; | |
6e23a06b | 29 | }; |
34e2fd14 | 30 | phpFpm = rec { |
a0c845b4 | 31 | serviceDeps = [ "mysql.service" "${environment}-piedsjaloux-key.service" ]; |
34e2fd14 IB |
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 | |
6e23a06b | 42 | php_admin_value[open_basedir] = "/run/keys/webapps/${environment}-piedsjaloux:${webappDir}:${varDir}:/tmp" |
c8e019b6 | 43 | php_admin_value[session.save_path] = "${varDir}/phpSessions" |
364eb3d0 | 44 | env[PATH] = ${lib.makeBinPath [ pkgs.apg pkgs.unzip ]} |
34e2fd14 IB |
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 | }; | |
e5073add | 58 | apache = rec { |
34e2fd14 IB |
59 | user = "wwwrun"; |
60 | group = "wwwrun"; | |
61 | modules = [ "proxy_fcgi" ]; | |
e5073add IB |
62 | webappName = "piedsjaloux_${environment}"; |
63 | root = "/run/current-system/webapps/${webappName}"; | |
34e2fd14 IB |
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 | ||
e5073add | 76 | <Directory ${root}> |
34e2fd14 IB |
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 | ||
7da3ceec | 119 | <Directory ${root}> |
34e2fd14 IB |
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 | |
c8e019b6 | 132 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions |
34e2fd14 IB |
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 | }; | |
85545c3f IB |
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 | |
6e23a06b | 155 | ln -sf /run/keys/webapps/${environment}-piedsjaloux app/config/parameters.yml |
85545c3f | 156 | rm -rf var/{logs,cache,data,miniatures,tmp} |
3c8d7f87 | 157 | ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/ |
85545c3f IB |
158 | ''; |
159 | }); | |
34e2fd14 IB |
160 | webRoot = "${webappDir}/web"; |
161 | }; | |
162 | in | |
163 | piedsjaloux |