]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/chloe/chloe.nix
Fix the SSL state for databases connections
[perso/Immae/Config/Nix.git] / nixops / modules / websites / chloe / chloe.nix
CommitLineData
9d90e7e2 1{ stdenv, lib, fetchzip, fetchurl, fetchedGitPrivate, sassc }:
7d8b50d3 2let
9d90e7e2
IB
3 chloe = { config }: rec {
4 environment = config.environment;
7d8b50d3
IB
5 phpFpm = rec {
6 socket = "/var/run/phpfpm/chloe-${environment}.sock";
9d90e7e2 7 pool = ''
7d8b50d3
IB
8 listen = ${socket}
9 user = ${apache.user}
10 group = ${apache.group}
11 listen.owner = ${apache.user}
12 listen.group = ${apache.group}
13 php_admin_value[upload_max_filesize] = 20M
14 php_admin_value[post_max_size] = 20M
15 ;php_admin_flag[log_errors] = on
091ae734 16 php_admin_value[open_basedir] = "${../commons/spip/spip_mes_options.php}:${configDir}:${webRoot}:${varDir}:/tmp"
c8e019b6 17 php_admin_value[session.save_path] = "${varDir}/phpSessions"
7d8b50d3 18 env[SPIP_CONFIG_DIR] = "${configDir}"
07f2f340
IB
19 env[SPIP_VAR_DIR] = "${varDir}"
20 env[SPIP_SITE] = "chloe-${environment}"
7d8b50d3
IB
21 env[SPIP_LDAP_BASE] = "dc=immae,dc=eu"
22 env[SPIP_LDAP_HOST] = "ldaps://ldap.immae.eu"
9d90e7e2
IB
23 env[SPIP_LDAP_SEARCH_DN] = "${config.ldap.dn}"
24 env[SPIP_LDAP_SEARCH_PW] = "${config.ldap.password}"
25 env[SPIP_LDAP_SEARCH] = "${config.ldap.search}"
7ebcaad5
IB
26 env[SPIP_MYSQL_HOST] = "${config.mysql.host}"
27 env[SPIP_MYSQL_PORT] = "${config.mysql.port}"
9d90e7e2
IB
28 env[SPIP_MYSQL_DB] = "${config.mysql.name}"
29 env[SPIP_MYSQL_USER] = "${config.mysql.user}"
30 env[SPIP_MYSQL_PASSWORD] = "${config.mysql.password}"
7d8b50d3
IB
31 ${if environment == "dev" then ''
32 pm = ondemand
33 pm.max_children = 5
34 pm.process_idle_timeout = 60
35 '' else ''
36 pm = dynamic
37 pm.max_children = 20
38 pm.start_servers = 2
39 pm.min_spare_servers = 1
40 pm.max_spare_servers = 3
41 ''}'';
42 };
43 apache = {
44 user = "wwwrun";
45 group = "wwwrun";
46 modules = [ "proxy_fcgi" ];
47 vhostConf = ''
48 RewriteEngine On
49 ${if environment == "prod" then ''
50 RewriteRule ^/news.rss /spip.php?page=backend&id_rubrique=1
51 '' else ""}
52
53 <FilesMatch "\.php$">
54 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
55 </FilesMatch>
56
57 <Directory ${webRoot}>
58 DirectoryIndex index.php index.htm index.html
59 Options -Indexes +FollowSymLinks +MultiViews +Includes
60 Include ${webRoot}/htaccess.txt
61
62 AllowOverride AuthConfig FileInfo Limit
63 Require all granted
64 </Directory>
65
7d8b50d3
IB
66 <DirectoryMatch "${webRoot}/squelettes">
67 Require all denied
68 </DirectoryMatch>
69
70 <FilesMatch "(.htaccess|rewrite-rules|.gitignore)$">
71 Require all denied
72 </FilesMatch>
73
74 ${if environment == "dev" then ''
75 <Location />
76 Use LDAPConnect
77 Require ldap-group cn=chloe.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
78 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://osteopathe-cc.fr\"></html>"
79 </Location>
6bd6d033
IB
80 '' else ''
81 Use Stats osteopathe-cc.fr
82 ''}
7d8b50d3
IB
83 '';
84 };
85 activationScript = {
86 deps = [ "wrappers" ];
87 text = ''
07f2f340 88 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} ${varDir}/IMG ${varDir}/tmp ${varDir}/local
c8e019b6 89 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
7d8b50d3
IB
90 '';
91 };
62a0946e 92 configDir = ./chloe_config_ + environment;
7d8b50d3
IB
93 varDir = "/var/lib/chloe_${environment}";
94 siteDir = stdenv.mkDerivation (fetchedGitPrivate ./chloe.json // rec {
95 buildPhase = ''
96 make
97 '';
98 installPhase = ''
99 cp -a . $out
100 '';
101 buildInputs = [ sassc ];
102 });
103 webRoot = stdenv.mkDerivation rec {
07f2f340 104 name = "chloe-${environment}-spip-${version}";
a718b966 105 version = "3.2.3";
7d8b50d3 106 src = fetchzip {
a718b966
IB
107 url = "https://files.spip.net/spip/archives/SPIP-v${version}.zip";
108 sha256 = "1r1mjvsnrp6mvkgjakvi3x4ms8m8k5mp93micbbg8r99fj7qlfkq";
7d8b50d3 109 };
091ae734 110 paches = [ ../commons/spip/spip_ldap_patch.patch ];
7d8b50d3
IB
111 buildPhase = ''
112 rm -rf IMG local tmp config/remove.txt
091ae734 113 ln -sf ${../commons/spip/spip_mes_options.php} config/mes_options.php
7d8b50d3 114 echo "Require all denied" > "config/.htaccess"
07f2f340 115 ln -sf ../../../../../${varDir}/{IMG,local} .
7d8b50d3
IB
116 '';
117 installPhase = ''
118 cp -a . $out
119 cp -a ${siteDir}/* $out
120 '';
121 };
122 };
123in
124 chloe