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