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