]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/packages/roundcubemail.nix
Add roundcubemail
[perso/Immae/Config/Nix.git] / virtual / packages / roundcubemail.nix
CommitLineData
d252d718
IB
1{ lib, checkEnv, writeText, stdenv, fetchurl }:
2let
3 roundcubemail = let
4 plugins = {};
5 in rec {
6 varDir = "/var/lib/roundcubemail";
7 # FIXME: initial sync
8 activationScript = {
9 deps = [ "wrappers" ];
10 text = ''
11 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
12 ${varDir}/cache
13 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
14 '';
15 };
16 config =
17 # FIXME: LOG_DESTINATION syslog?
18 assert checkEnv "NIXOPS_ROUNDCUBEMAIL_PSQL_URL";
19 assert checkEnv "NIXOPS_ROUNDCUBEMAIL_SECRET";
20 writeText "config.php" ''
21 <?php
22 $config['db_dsnw'] = '${builtins.getEnv "NIXOPS_ROUNDCUBEMAIL_PSQL_URL"}';
23 $config['default_host'] = 'ssl://mail.immae.eu';
24 $config['imap_conn_options'] = array("ssl" => array("verify_peer" => false));
25 $config['smtp_server'] = 'tls://mail.immae.eu';
26
27 $config['imap_cache'] = 'db';
28 $config['messages_cache'] = 'db';
29
30 $config['support_url'] = ''';
31
32 $config['des_key'] = '${builtins.getEnv "NIXOPS_ROUNDCUBEMAIL_SECRET"}';
33
34 $config['plugins'] = array();
35
36 $config['language'] = 'fr_FR';
37
38 $config['drafts_mbox'] = 'Mail/Drafts';
39 $config['junk_mbox'] = 'Mail/Spam';
40 $config['sent_mbox'] = 'Mail/sent';
41 $config['trash_mbox'] = ''';
42 $config['default_folders'] = array('INBOX', 'Mail/Drafts', 'Mail/sent', 'Mail/Spam', ''');
43 $config['draft_autosave'] = 60;
44 $config['enable_installer'] = false;
45 $config['log_driver'] = 'stdout';
46 $config['temp_dir'] = '${varDir}/cache';
47 $config['debug_level'] = 1;
48 '';
49 webRoot = stdenv.mkDerivation rec {
50 version = "1.3.8";
51 name = "roundcubemail-${version}";
52 src= fetchurl {
53 url = "https://github.com/roundcube/roundcubemail/releases/download/${version}/${name}-complete.tar.gz";
54 sha256 = "018djad7ygfl9c9f2l2j42qkg31ml3hs2f01f0dk361zckwk77n4";
55 };
56 buildPhase = ''
57 sed -i \
58 -e "s|RCUBE_INSTALL_PATH . 'temp.*|'${varDir}/cache';|" \
59 config/defaults.inc.php
60 '';
61 installPhase = ''
62 cp -a . $out
63 ln -s ${config} $out/config/config.inc.php
64 ${builtins.concatStringsSep "\n" (
65 lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/plugins/${name}") plugins
66 )}
67 '';
68 };
69 apache = {
70 user = "wwwrun";
71 group = "wwwrun";
72 modules = [ "proxy_fcgi" ];
73 vhostConf = ''
74 Alias /roundcube "${webRoot}"
75 <Directory "${webRoot}">
76 DirectoryIndex index.php
77 AllowOverride All
78 Options FollowSymlinks
79 Require all granted
80
81 <FilesMatch "\.php$">
82 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
83 </FilesMatch>
84 </Directory>
85 '';
86 };
87 phpFpm = rec {
88 basedir = builtins.concatStringsSep ":" (
89 [ webRoot config varDir ]
90 ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
91 socket = "/var/run/phpfpm/roundcubemail.sock";
92 pool = ''
93 listen = ${socket}
94 user = ${apache.user}
95 group = ${apache.group}
96 listen.owner = ${apache.user}
97 listen.group = ${apache.group}
98 pm = ondemand
99 pm.max_children = 60
100 pm.process_idle_timeout = 60
101
102 ; Needed to avoid clashes in browser cookies (same domain)
103 php_value[session.name] = RoundcubemailPHPSESSID
104 php_admin_value[open_basedir] = "${basedir}:/tmp"
105 php_admin_value[session.save_path] = "${varDir}/phpSessions"
106 '';
107 };
108 };
109in
110 roundcubemail