]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/ludivine/ludivinecassal.nix
Move Ludivine website to pkgs
[perso/Immae/Config/Nix.git] / nixops / modules / websites / ludivine / ludivinecassal.nix
CommitLineData
b3c0779f
IB
1{ config, ludivinecassal, pkgs, ruby, sass, imagemagick }:
2rec {
3 app = ludivinecassal.override { inherit (config) environment; };
4 varDir = "/var/lib/ludivinecassal_${app.environment}";
5 keys = [{
6 dest = "webapps/${app.environment}-ludivinecassal";
7 user = apache.user;
8 group = apache.group;
9 permissions = "0400";
10 text = ''
11 # This file is auto-generated during the composer install
12 parameters:
13 database_host: ${config.mysql.host}
14 database_port: ${config.mysql.port}
15 database_name: ${config.mysql.name}
16 database_user: ${config.mysql.user}
17 database_password: ${config.mysql.password}
18 database_server_version: ${pkgs.mariadb.mysqlVersion}
19 mailer_transport: smtp
20 mailer_host: 127.0.0.1
21 mailer_user: null
22 mailer_password: null
23 secret: ${config.secret}
24 ldap_host: ldap.immae.eu
25 ldap_port: 636
26 ldap_version: 3
27 ldap_ssl: true
28 ldap_tls: false
29 ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu'
30 ldap_base_dn: 'dc=immae,dc=eu'
31 ldap_search_dn: '${config.ldap.dn}'
32 ldap_search_password: '${config.ldap.password}'
33 ldap_search_filter: '${config.ldap.search}'
34 leapt_im:
35 binary_path: ${imagemagick}/bin
36 assetic:
37 sass: ${sass}/bin/sass
38 ruby: ${ruby}/bin/ruby
39 '';
40 }];
41 phpFpm = rec {
42 preStart = ''
43 if [ ! -f "${app.varDir}/currentWebappDir" -o \
44 ! -f "${app.varDir}/currentKey" -o \
45 "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \
46 || ! sha512sum -c --status ${app.varDir}/currentKey; then
47 pushd ${app} > /dev/null
48 /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${app.environment} cache:clear --no-warmup
49 popd > /dev/null
50 echo -n "${app}" > ${app.varDir}/currentWebappDir
51 sha512sum /var/secrets/webapps/${app.environment}-ludivinecassal > ${app.varDir}/currentKey
52 fi
e42ba74f 53 '';
b3c0779f
IB
54 serviceDeps = [ "mysql.service" ];
55 socket = "/var/run/phpfpm/ludivinecassal-${app.environment}.sock";
56 pool = ''
57 listen = ${socket}
58 user = ${apache.user}
59 group = ${apache.group}
60 listen.owner = ${apache.user}
61 listen.group = ${apache.group}
62 php_admin_value[upload_max_filesize] = 20M
63 php_admin_value[post_max_size] = 20M
64 ;php_admin_flag[log_errors] = on
65 php_admin_value[open_basedir] = "/var/secrets/webapps/${app.environment}-ludivinecassal:${app}:${app.varDir}:/tmp"
66 php_admin_value[session.save_path] = "${app.varDir}/phpSessions"
67 ${if app.environment == "dev" then ''
68 pm = ondemand
69 pm.max_children = 5
70 pm.process_idle_timeout = 60
71 env[SYMFONY_DEBUG_MODE] = "yes"
72 '' else ''
73 pm = dynamic
74 pm.max_children = 20
75 pm.start_servers = 2
76 pm.min_spare_servers = 1
77 pm.max_spare_servers = 3
78 ''}'';
79 };
80 apache = rec {
81 user = "wwwrun";
82 group = "wwwrun";
83 modules = [ "proxy_fcgi" ];
84 webappName = "ludivine_${app.environment}";
85 root = "/run/current-system/webapps/${webappName}";
86 vhostConf = ''
87 <FilesMatch "\.php$">
88 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
89 </FilesMatch>
e42ba74f 90
b3c0779f
IB
91 ${if app.environment == "dev" then ''
92 <Location />
93 Use LDAPConnect
94 Require ldap-group cn=ludivine.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
95 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.com\"></html>"
96 </Location>
e42ba74f 97
b3c0779f
IB
98 <Directory ${root}>
99 Options Indexes FollowSymLinks MultiViews Includes
100 AllowOverride None
101 Require all granted
e42ba74f 102
b3c0779f 103 DirectoryIndex app_dev.php
e42ba74f 104
b3c0779f
IB
105 <IfModule mod_negotiation.c>
106 Options -MultiViews
107 </IfModule>
e42ba74f 108
b3c0779f
IB
109 <IfModule mod_rewrite.c>
110 RewriteEngine On
e42ba74f 111
b3c0779f
IB
112 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
113 RewriteRule ^(.*) - [E=BASE:%1]
e42ba74f 114
b3c0779f
IB
115 # Maintenance script
116 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
117 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
118 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
119 ErrorDocument 503 /maintenance.php
e42ba74f 120
b3c0779f
IB
121 # Sets the HTTP_AUTHORIZATION header removed by Apache
122 RewriteCond %{HTTP:Authorization} .
123 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
e42ba74f 124
b3c0779f
IB
125 RewriteCond %{ENV:REDIRECT_STATUS} ^$
126 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
e42ba74f 127
b3c0779f
IB
128 # If the requested filename exists, simply serve it.
129 # We only want to let Apache serve files and not directories.
130 RewriteCond %{REQUEST_FILENAME} -f
131 RewriteRule ^ - [L]
e42ba74f 132
b3c0779f
IB
133 # Rewrite all other queries to the front controller.
134 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
135 </IfModule>
e42ba74f 136
b3c0779f
IB
137 </Directory>
138 '' else ''
139 Use Stats ludivinecassal.com
34e2fd14 140
b3c0779f
IB
141 <Directory ${root}>
142 Options Indexes FollowSymLinks MultiViews Includes
143 AllowOverride All
144 Require all granted
145 </Directory>
146 ''}
147 '';
148 };
149 activationScript = {
150 deps = [ "wrappers" ];
151 text = ''
152 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${app.varDir}
153 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${app.varDir}/tmp
154 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${app.varDir}/phpSessions
155 '';
e42ba74f 156 };
b3c0779f 157}