]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/ludivine/integration.nix
Rework integration websites
[perso/Immae/Config/Nix.git] / modules / private / websites / ludivine / integration.nix
1 { lib, pkgs, config, ... }:
2 let
3 secrets = config.myEnv.websites.ludivine.integration;
4 cfg = config.myServices.websites.ludivine.integration;
5 ftpRoot = "/var/lib/ludivine_integration";
6 phpRoot = "${ftpRoot}/php";
7 webRoot = "${phpRoot}/web";
8 varDir = "${ftpRoot}/var";
9 sessionDir = "${ftpRoot}/sessions";
10 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Ludivine";
11 branch = "test";
12 in {
13 options.myServices.websites.ludivine.integration.enable = lib.mkEnableOption "enable Ludivine's website in integration";
14
15 config = lib.mkIf cfg.enable {
16 services.phpfpm.pools.ludivine_integration = {
17 user = config.services.httpd.Inte.user;
18 group = config.services.httpd.Inte.group;
19 settings = {
20 "listen.owner" = config.services.httpd.Inte.user;
21 "listen.group" = config.services.httpd.Inte.group;
22 "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
23 ftpRoot
24 config.secrets.fullPaths."websites/ludivine/integration"
25 "/tmp"
26 ];
27 "php_admin_value[session.save_path]" = sessionDir;
28 "php_admin_value[upload_max_filesize]" = "20M";
29 "php_admin_value[post_max_size]" = "20M";
30 #"php_admin_flag[log_errors]" = "on";
31 "pm" = "ondemand";
32 "pm.max_children" = "5";
33 "pm.process_idle_timeout" = "60";
34 };
35 phpEnv = {
36 SYMFONY_DEBUG_MODE = "\"yes\"";
37 };
38 phpPackage = pkgs.php72;
39 };
40 systemd.services."phpfpm-ludivine_integration" = {
41 after = lib.mkAfter ["mysql.service"];
42 wants = ["mysql.service"];
43 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ];
44 preStart = let
45 script = pkgs.writeScriptBin "ludivine-integration-pre" ''
46 #! ${pkgs.stdenv.shell}
47
48 [ -f ${packagePath}/${branch}.tar.gz ] || exit 1
49
50 cd ${ftpRoot}
51 if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then
52 tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new
53 if [ -d php ]; then
54 mv php php_old
55 fi
56 mv php_new php
57 fi
58 cd php
59 rm -rf var/{logs,cache,data,miniatures,tmp}
60 ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/
61 ln -sf ${config.secrets.fullPaths."websites/ludivine/integration"} app/config/parameters.yml
62 SYMFONY_ENV=dev ./bin/console --env=dev cache:clear --no-warmup
63 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
64 '';
65 in
66 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/ludivine-integration-pre";
67 postStart = let
68 script = pkgs.writeScriptBin "ludivine-integration-post" ''
69 #! ${pkgs.stdenv.shell}
70
71 cd ${ftpRoot}
72 if [ -d php_old ]; then
73 rm -rf php_old
74 fi
75 '';
76 in
77 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/ludivine-integration-post";
78 serviceConfig.TimeoutStartSec="infinity";
79 };
80 services.filesWatcher.phpfpm-ludivine_integration = {
81 restart = true;
82 paths = [ "${packagePath}/${branch}.tar.gz" ];
83 };
84
85 system.activationScripts.ludivine_integration = {
86 deps = [];
87 text = ''
88 install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir}
89 '';
90 };
91
92 secrets.keys."websites/ludivine/integration" = {
93 user = config.services.httpd.Inte.user;
94 group = config.services.httpd.Inte.group;
95 permissions = "0400";
96 text = ''
97 # This file is auto-generated during the composer install
98 parameters:
99 database_host: ${secrets.mysql.host}
100 database_port: ${secrets.mysql.port}
101 database_name: ${secrets.mysql.database}
102 database_user: ${secrets.mysql.user}
103 database_password: ${secrets.mysql.password}
104 database_server_version: ${pkgs.mariadb.mysqlVersion}
105 mailer_transport: smtp
106 mailer_host: 127.0.0.1
107 mailer_user: null
108 mailer_password: null
109 secret: ${secrets.secret}
110 ldap_host: ldap.immae.eu
111 ldap_port: 636
112 ldap_version: 3
113 ldap_ssl: true
114 ldap_tls: false
115 ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu'
116 ldap_base_dn: 'dc=immae,dc=eu'
117 ldap_search_dn: '${secrets.ldap.dn}'
118 ldap_search_password: '${secrets.ldap.password}'
119 ldap_search_filter: '${secrets.ldap.filter}'
120 leapt_im:
121 binary_path: ${pkgs.imagemagick}/bin
122 assetic:
123 sass: ${pkgs.sass}/bin/sass
124 ruby: ${pkgs.ruby}/bin/ruby
125 '';
126 };
127
128 services.websites.env.integration.vhostConfs.ludivine_integration = {
129 certName = "integration";
130 addToCerts = true;
131 hosts = [ "test.lc.immae.dev" ];
132 root = webRoot;
133 extraConfig = [
134 ''
135 <FilesMatch "\.php$">
136 SetHandler "proxy:unix:${config.services.phpfpm.pools.ludivine_integration.socket}|fcgi://localhost"
137 </FilesMatch>
138
139 <Location />
140 Use LDAPConnect
141 Require ldap-group cn=lc.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu
142 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.com\"></html>"
143 </Location>
144
145 <Directory ${webRoot}>
146 Options Indexes FollowSymLinks MultiViews Includes
147 AllowOverride None
148 Require all granted
149
150 DirectoryIndex app_dev.php
151
152 <IfModule mod_negotiation.c>
153 Options -MultiViews
154 </IfModule>
155
156 <IfModule mod_rewrite.c>
157 RewriteEngine On
158
159 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
160 RewriteRule ^(.*) - [E=BASE:%1]
161
162 # Maintenance script
163 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
164 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
165 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
166 ErrorDocument 503 /maintenance.php
167
168 # Sets the HTTP_AUTHORIZATION header removed by Apache
169 RewriteCond %{HTTP:Authorization} .
170 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
171
172 RewriteCond %{ENV:REDIRECT_STATUS} ^$
173 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
174
175 # If the requested filename exists, simply serve it.
176 # We only want to let Apache serve files and not directories.
177 RewriteCond %{REQUEST_FILENAME} -f
178 RewriteRule ^ - [L]
179
180 # Rewrite all other queries to the front controller.
181 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
182 </IfModule>
183
184 </Directory>
185 ''
186 ];
187 };
188 };
189 }