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