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