]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/packages/chloe.nix
Add Chloé's website
[perso/Immae/Config/Nix.git] / virtual / packages / chloe.nix
CommitLineData
7d8b50d3
IB
1{ stdenv, lib, checkEnv, fetchzip, fetchurl, fetchedGitPrivate, sassc }:
2let
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_LDAP_BASE] = "dc=immae,dc=eu"
27 env[SPIP_LDAP_HOST] = "ldaps://ldap.immae.eu"
28 env[SPIP_LDAP_SEARCH_DN] = "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_LDAP_DN"}"
29 env[SPIP_LDAP_SEARCH_PW] = "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_LDAP_PASSWORD"}"
30 env[SPIP_LDAP_SEARCH] = "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_LDAP_SEARCH"}"
31 env[SPIP_MYSQL_HOST] = "db-1.immae.eu"
32 env[SPIP_MYSQL_DB] = "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_DB"}"
33 env[SPIP_MYSQL_USER] = "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER"}"
34 env[SPIP_MYSQL_PASSWORD] = "${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD"}"
35 ${if environment == "dev" then ''
36 pm = ondemand
37 pm.max_children = 5
38 pm.process_idle_timeout = 60
39 '' else ''
40 pm = dynamic
41 pm.max_children = 20
42 pm.start_servers = 2
43 pm.min_spare_servers = 1
44 pm.max_spare_servers = 3
45 ''}'';
46 };
47 apache = {
48 user = "wwwrun";
49 group = "wwwrun";
50 modules = [ "proxy_fcgi" ];
51 vhostConf = ''
52 RewriteEngine On
53 ${if environment == "prod" then ''
54 RewriteRule ^/news.rss /spip.php?page=backend&id_rubrique=1
55 '' else ""}
56
57 <FilesMatch "\.php$">
58 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
59 </FilesMatch>
60
61 <Directory ${webRoot}>
62 DirectoryIndex index.php index.htm index.html
63 Options -Indexes +FollowSymLinks +MultiViews +Includes
64 Include ${webRoot}/htaccess.txt
65
66 AllowOverride AuthConfig FileInfo Limit
67 Require all granted
68 </Directory>
69
70 <DirectoryMatch "${varDir}/tmp">
71 Require all denied
72 </DirectoryMatch>
73
74 <DirectoryMatch "${webRoot}/squelettes">
75 Require all denied
76 </DirectoryMatch>
77
78 <FilesMatch "(.htaccess|rewrite-rules|.gitignore)$">
79 Require all denied
80 </FilesMatch>
81
82 ${if environment == "dev" then ''
83 <Location />
84 Use LDAPConnect
85 Require ldap-group cn=chloe.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
86 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://osteopathe-cc.fr\"></html>"
87 </Location>
88 '' else ""}
89 '';
90 };
91 activationScript = {
92 deps = [ "wrappers" ];
93 text = ''
94 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} ${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 = "spip-${version}";
110 version = "3.2";
111 src = fetchzip {
112 url = "http://files.spip.org/spip/stable/${name}.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,tmp} .
121 '';
122 installPhase = ''
123 cp -a . $out
124 cp -a ${siteDir}/* $out
125 '';
126 };
127 };
128in
129 chloe