]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/piedsjaloux/integration.nix
d8790cc93a6a4d828723f467af0863c7cf536775
[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 app = pkgs.callPackage ./app {
5 environment = secrets.environment;
6 varDir = "/var/lib/piedsjaloux_integration";
7 secretsPath = config.secrets.fullPaths."websites/piedsjaloux/integration";
8 };
9 cfg = config.myServices.websites.piedsjaloux.integration;
10 pcfg = config.services.phpApplication;
11 texlive = pkgs.texlive.combine { inherit (pkgs.texlive) attachfile preprint scheme-small; };
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.duplyBackup.profiles.piedsjaloux_integration.rootDir = app.varDir;
17 services.phpApplication.apps.piedsjaloux_integration = {
18 websiteEnv = "integration";
19 httpdUser = config.services.httpd.Inte.user;
20 httpdGroup = config.services.httpd.Inte.group;
21 inherit (app) webRoot varDir;
22 varDirPaths = {
23 "tmp" = "0700";
24 };
25 inherit app;
26 serviceDeps = [ "mysql.service" ];
27 preStartActions = [
28 "./bin/console --env=${app.environment} cache:clear --no-warmup"
29 ];
30 phpOpenbasedir = [ "/tmp" ];
31 phpPool = {
32 "php_admin_value[upload_max_filesize]" = "20M";
33 "php_admin_value[post_max_size]" = "20M";
34 #"php_admin_flag[log_errors]" = "on";
35 "pm" = "ondemand";
36 "pm.max_children" = "5";
37 "pm.process_idle_timeout" = "60";
38 };
39 phpEnv = {
40 PATH = lib.makeBinPath [
41 pkgs.apg pkgs.unzip
42 # below ones don't need to be in the PATH but they’re used in
43 # secrets
44 pkgs.imagemagick texlive
45 ];
46 SYMFONY_DEBUG_MODE = "\"yes\"";
47 };
48 phpWatchFiles = [
49 app.secretsPath
50 ];
51 };
52
53 secrets.keys = [
54 {
55 dest = "websites/piedsjaloux/integration";
56 user = config.services.httpd.Inte.user;
57 group = config.services.httpd.Inte.group;
58 permissions = "0400";
59 text = ''
60 # This file is auto-generated during the composer install
61 parameters:
62 database_host: ${secrets.mysql.host}
63 database_port: ${secrets.mysql.port}
64 database_name: ${secrets.mysql.database}
65 database_user: ${secrets.mysql.user}
66 database_password: ${secrets.mysql.password}
67 database_server_version: ${pkgs.mariadb.mysqlVersion}
68 mailer_transport: smtp
69 mailer_host: 127.0.0.1
70 mailer_user: null
71 mailer_password: null
72 secret: ${secrets.secret}
73 pdflatex: "${texlive}/bin/pdflatex"
74 leapt_im:
75 binary_path: ${pkgs.imagemagick}/bin
76 '';
77 }
78 ];
79
80 services.websites.env.integration.vhostConfs.piedsjaloux_integration = {
81 certName = "integration";
82 addToCerts = true;
83 hosts = [ "piedsjaloux.immae.eu" ];
84 root = pcfg.webappDirs.piedsjaloux_integration;
85 extraConfig = [
86 ''
87 <FilesMatch "\.php$">
88 SetHandler "proxy:unix:${pcfg.phpListenPaths.piedsjaloux_integration}|fcgi://localhost"
89 </FilesMatch>
90
91 <Location />
92 Use LDAPConnect
93 Require ldap-group cn=piedsjaloux.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
94 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://piedsjaloux.fr\"></html>"
95 </Location>
96
97 <Directory ${pcfg.webappDirs.piedsjaloux_integration}>
98 Options Indexes FollowSymLinks MultiViews Includes
99 AllowOverride None
100 Require all granted
101
102 DirectoryIndex app_dev.php
103
104 <IfModule mod_negotiation.c>
105 Options -MultiViews
106 </IfModule>
107
108 <IfModule mod_rewrite.c>
109 RewriteEngine On
110
111 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
112 RewriteRule ^(.*) - [E=BASE:%1]
113
114 # Maintenance script
115 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
116 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
117 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
118 ErrorDocument 503 /maintenance.php
119
120 # Sets the HTTP_AUTHORIZATION header removed by Apache
121 RewriteCond %{HTTP:Authorization} .
122 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
123
124 RewriteCond %{ENV:REDIRECT_STATUS} ^$
125 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
126
127 # If the requested filename exists, simply serve it.
128 # We only want to let Apache serve files and not directories.
129 RewriteCond %{REQUEST_FILENAME} -f
130 RewriteRule ^ - [L]
131
132 # Rewrite all other queries to the front controller.
133 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
134 </IfModule>
135
136 </Directory>
137 ''
138 ];
139 };
140 };
141 }