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