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