]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/packages/ludivinecassal.nix
Add stats for ludivinecassal.com
[perso/Immae/Config/Nix.git] / virtual / packages / ludivinecassal.nix
CommitLineData
e42ba74f
IB
1{ lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages, ruby, sass, imagemagick }:
2let
3 ludivinecassal = { environment ? "dev" }: rec {
4 varPrefix = "LUDIVINECASSAL";
5 varDir = "/var/lib/ludivinecassal_${environment}";
6 envName= lib.strings.toUpper environment;
7 configRoot =
8 assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD";
9 assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER";
10 assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_NAME";
11 assert checkEnv "NIXOPS_${varPrefix}_${envName}_SECRET";
12 assert checkEnv "NIXOPS_${varPrefix}_${envName}_LDAP_PASSWORD";
13 assert checkEnv "NIXOPS_${varPrefix}_${envName}_LDAP_SEARCH_DN";
14 assert checkEnv "NIXOPS_${varPrefix}_${envName}_LDAP_SEARCH_FILTER";
15 writeText "parameters.yml" ''
16 # This file is auto-generated during the composer install
17 parameters:
18 database_host: db-1.immae.eu
19 database_port: null
20 database_name: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_NAME"}
21 database_user: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER"}
22 database_password: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD"}
23 mailer_transport: smtp
24 mailer_host: mail.immae.eu
25 mailer_user: null
26 mailer_password: null
27 secret: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"}
28 ldap_host: ldap.immae.eu
29 ldap_port: 636
30 ldap_version: 3
31 ldap_ssl: true
32 ldap_tls: false
33 ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu'
34 ldap_base_dn: 'dc=immae,dc=eu'
35 ldap_search_dn: '${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_LDAP_SEARCH_DN"}'
36 ldap_search_password: '${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_LDAP_PASSWORD"}'
37 ldap_search_filter: '${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_LDAP_SEARCH_FILTER"}'
38 leapt_im:
39 binary_path: ${imagemagick}/bin
40 assetic:
41 sass: ${sass}/bin/sass
42 ruby: ${ruby}/bin/ruby
43 '';
44 phpFpm = rec {
45 socket = "/var/run/phpfpm/ludivinecassal-${environment}.sock";
46 pool = ''
47 listen = ${socket}
48 user = ${apache.user}
49 group = ${apache.group}
50 listen.owner = ${apache.user}
51 listen.group = ${apache.group}
52 php_admin_value[upload_max_filesize] = 20M
53 php_admin_value[post_max_size] = 20M
54 ;php_admin_flag[log_errors] = on
55 php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp"
56 ${if environment == "dev" then ''
57 pm = ondemand
58 pm.max_children = 5
59 pm.process_idle_timeout = 60
60 env[SYMFONY_DEBUG_MODE] = "yes"
61 '' else ''
62 pm = dynamic
63 pm.max_children = 20
64 pm.start_servers = 2
65 pm.min_spare_servers = 1
66 pm.max_spare_servers = 3
67 ''}'';
68 };
69 apache = {
70 user = "wwwrun";
71 group = "wwwrun";
72 modules = [ "proxy_fcgi" ];
73 vhostConf = ''
2f2b578b
IB
74 Use Stats ludivinecassal.com
75
e42ba74f
IB
76 <FilesMatch "\.php$">
77 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
78 </FilesMatch>
79
80 ${if environment == "dev" then ''
81 <Location />
82 Use LDAPConnect
83 Require ldap-group cn=ludivine.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
84 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.com\"></html>"
85 </Location>
86
87 <Directory ${webRoot}>
88 Options Indexes FollowSymLinks MultiViews Includes
89 AllowOverride None
90 Require all granted
91
92 DirectoryIndex app_dev.php
93
94 <IfModule mod_negotiation.c>
95 Options -MultiViews
96 </IfModule>
97
98 <IfModule mod_rewrite.c>
99 RewriteEngine On
100
101 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
102 RewriteRule ^(.*) - [E=BASE:%1]
103
104 # Maintenance script
105 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
106 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
107 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
108 ErrorDocument 503 /maintenance.php
109
110 # Sets the HTTP_AUTHORIZATION header removed by Apache
111 RewriteCond %{HTTP:Authorization} .
112 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
113
114 RewriteCond %{ENV:REDIRECT_STATUS} ^$
115 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
116
117 # If the requested filename exists, simply serve it.
118 # We only want to let Apache serve files and not directories.
119 RewriteCond %{REQUEST_FILENAME} -f
120 RewriteRule ^ - [L]
121
122 # Rewrite all other queries to the front controller.
123 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
124 </IfModule>
125
126 </Directory>
127 '' else ''
128 <Directory ${webRoot}>
129 Options Indexes FollowSymLinks MultiViews Includes
130 AllowOverride All
131 Require all granted
132 </Directory>
133 ''}
134 '';
135 };
136 activationScript = {
137 deps = [ "wrappers" ];
138 text = ''
139 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}
140 if [ ! -f "${varDir}/currentWebappDir" -o \
141 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
142 pushd ${webappDir} > /dev/null
143 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
144 popd > /dev/null
145 echo -n "${webappDir}" > ${varDir}/currentWebappDir
146 fi
147 '';
148 };
149 webappDir = stdenv.mkDerivation (fetchedGitPrivate ./ludivinecassal_master.json // rec {
150 # FIXME: can we do better than symlink?
151 # FIXME: initial sync
152 # FIXME: backup
153 # FIXME: miniatures and data need to be in the same dir due to a
154 # bug in leapt.im (searches for data/../miniatures)
155 buildPhase = ''
156 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
157 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
158
159 ln -sf ${configRoot} app/config/parameters.yml
160 sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json
161 ${if environment == "dev" then ''
162 composer install
163 '' else ''
164 SYMFONY_ENV=prod composer install --no-dev
165 ''}
166 rm -rf var
167 ln -sf ../../../../../${varDir} var
168 '';
169 installPhase = ''
170 cp -a . $out
171 '';
172 buildInputs = [
173 php git cacert phpPackages.composer sass
174 ];
175 });
176 webRoot = "${webappDir}/web";
177 };
178in
179 ludivinecassal