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