]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/piedsjaloux/piedsjaloux.nix
Unconfigure e-mail for symfony websites
[perso/Immae/Config/Nix.git] / nixops / modules / websites / piedsjaloux / piedsjaloux.nix
CommitLineData
85545c3f 1{ pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, fetchurl, fetchgit, texlive, imagemagick }:
34e2fd14 2let
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:
7ebcaad5
IB
10 database_host: ${config.mysql.host}
11 database_port: ${config.mysql.port}
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 16 mailer_transport: smtp
c9af72bc 17 mailer_host: 127.0.0.1
34e2fd14
IB
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"
364eb3d0 38 env[PATH] = ${lib.makeBinPath [ pkgs.apg pkgs.unzip ]}
34e2fd14
IB
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 = {
53 user = "wwwrun";
54 group = "wwwrun";
55 modules = [ "proxy_fcgi" ];
56 vhostConf = ''
57 <FilesMatch "\.php$">
58 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
59 </FilesMatch>
60
61 ${if environment == "dev" then ''
62 <Location />
63 Use LDAPConnect
64 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
65 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>"
66 </Location>
67
68 <Directory ${webRoot}>
69 Options Indexes FollowSymLinks MultiViews Includes
70 AllowOverride None
71 Require all granted
72
73 DirectoryIndex app_dev.php
74
75 <IfModule mod_negotiation.c>
76 Options -MultiViews
77 </IfModule>
78
79 <IfModule mod_rewrite.c>
80 RewriteEngine On
81
82 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
83 RewriteRule ^(.*) - [E=BASE:%1]
84
85 # Maintenance script
86 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
87 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
88 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
89 ErrorDocument 503 /maintenance.php
90
91 # Sets the HTTP_AUTHORIZATION header removed by Apache
92 RewriteCond %{HTTP:Authorization} .
93 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
94
95 RewriteCond %{ENV:REDIRECT_STATUS} ^$
96 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
97
98 # If the requested filename exists, simply serve it.
99 # We only want to let Apache serve files and not directories.
100 RewriteCond %{REQUEST_FILENAME} -f
101 RewriteRule ^ - [L]
102
103 # Rewrite all other queries to the front controller.
104 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
105 </IfModule>
106
107 </Directory>
108 '' else ''
109 Use Stats piedsjaloux.fr
110
111 <Directory ${webRoot}>
112 Options Indexes FollowSymLinks MultiViews Includes
113 AllowOverride All
114 Require all granted
115 </Directory>
116 ''}
117 '';
118 };
119 activationScript = {
120 deps = [ "wrappers" ];
121 text = ''
122 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
123 ${varDir}/tmp
c8e019b6 124 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
34e2fd14
IB
125 if [ ! -f "${varDir}/currentWebappDir" -o \
126 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
127 pushd ${webappDir} > /dev/null
128 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
129 popd > /dev/null
130 echo -n "${webappDir}" > ${varDir}/currentWebappDir
131 fi
132 '';
133 };
85545c3f
IB
134 webappDir = composerEnv.buildPackage (
135 import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } //
136 fetchedGitPrivate ./piedsjaloux.json //
137 rec {
138 noDev = (environment == "prod");
139 preInstall = ''
140 export SYMFONY_ENV="${environment}"
141 '';
142 # /!\ miniatures and data need to be in the same physical dir due to a
143 # bug in leapt.im (searches for data/../miniatures)
144 postInstall = ''
145 cd $out
146 rm app/config/parameters.yml
147 ln -sf ${configRoot} app/config/parameters.yml
148 rm -rf var/{logs,cache,data,miniatures,tmp}
149 ln -sf ../../../../../../../${varDir}/{logs,cache,data,miniatures,tmp} var/
150 '';
151 });
34e2fd14
IB
152 webRoot = "${webappDir}/web";
153 };
154in
155 piedsjaloux