aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites/tools/tools/roundcubemail.nix
blob: 8974d1bbbe2e50a08e5f1df33ec647fe4f2959cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{ env, roundcubemail, roundcubemail-plugins, roundcubemail-skins, phpPackages, apacheHttpd }:
rec {
  varDir = "/var/lib/roundcubemail";
  activationScript = {
    deps = [ "wrappers" ];
    text = ''
      install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
        ${varDir}/cache ${varDir}/logs
      install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
    '';
  };
  keys = [{
    dest = "webapps/tools-roundcube";
    user = apache.user;
    group = apache.group;
    permissions = "0400";
    text = ''
      <?php
        $config['db_dsnw'] = '${env.psql_url}';
        $config['default_host'] = 'ssl://mail.immae.eu';
        $config['imap_conn_options'] = array("ssl" => array("verify_peer" => false));
        $config['smtp_server'] = 'tls://mail.immae.eu';
        $config['smtp_port'] = '25';
        $config['managesieve_host'] = 'mail.immae.eu';
        $config['managesieve_port'] = '4190';
        $config['managesieve_usetls'] = true;
        $config['managesieve_conn_options'] = array("ssl" => array("verify_peer" => false));

        $config['imap_cache'] = 'db';
        $config['messages_cache'] = 'db';

        $config['support_url'] = ''';

        $config['des_key'] = '${env.secret}';

        $config['skin'] = 'elastic';
        $config['plugins'] = array(
          'attachment_reminder',
          'emoticons',
          'filesystem_attachments',
          'hide_blockquote',
          'identicon',
          'identity_select',
          'jqueryui',
          'managesieve',
          'newmail_notifier',
          'vcard_attachments',
          'zipdownload',

          'automatic_addressbook',
          'message_highlight',
          'carddav',
          // Ne marche pas ?: 'ident_switch',
          // Ne marche pas ?: 'thunderbird_labels',
        );

        $config['language'] = 'fr_FR';

        $config['drafts_mbox'] = 'Mail/Drafts';
        $config['junk_mbox'] = 'Mail/Spam';
        $config['sent_mbox'] = 'Mail/sent';
        $config['trash_mbox'] = ''';
        $config['default_folders'] = array('INBOX', 'Mail/Drafts', 'Mail/sent', 'Mail/Spam', ''');
        $config['draft_autosave'] = 60;
        $config['enable_installer'] = false;
        $config['log_driver'] = 'file';
        $config['temp_dir'] = '${varDir}/cache';
        $config['mime_types'] = '${apacheHttpd}/conf/mime.types';
    '';
  }];
  webRoot = (roundcubemail.override { roundcube_config = "/var/secrets/webapps/tools-roundcube"; }).withPlugins
    (builtins.attrValues roundcubemail-plugins) (builtins.attrValues roundcubemail-skins);
  apache = rec {
    user = "wwwrun";
    group = "wwwrun";
    modules = [ "proxy_fcgi" ];
    webappName = "tools_roundcubemail";
    root = "/run/current-system/webapps/${webappName}";
    vhostConf = ''
    Alias /roundcube "${root}"
    <Directory "${root}">
        DirectoryIndex index.php
        AllowOverride All
        Options FollowSymlinks
        Require all granted

        <FilesMatch "\.php$">
          SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
        </FilesMatch>
      </Directory>
      '';
  };
  phpFpm = rec {
    serviceDeps = [ "postgresql.service" ];
    basedir = builtins.concatStringsSep ":" (
      [ webRoot "/var/secrets/webapps/tools-roundcube" varDir ]
      ++ webRoot.plugins
      ++ webRoot.skins);
    phpConfig = ''
      date.timezone = 'CET'
      extension=${phpPackages.imagick}/lib/php/extensions/imagick.so
      '';
    socket = "/var/run/phpfpm/roundcubemail.sock";
    pool = ''
      user = ${apache.user}
      group = ${apache.group}
      listen.owner = ${apache.user}
      listen.group = ${apache.group}
      pm = ondemand
      pm.max_children = 60
      pm.process_idle_timeout = 60

      ; Needed to avoid clashes in browser cookies (same domain)
      php_value[session.name] = RoundcubemailPHPSESSID
      php_admin_value[upload_max_filesize] = 200M
      php_admin_value[post_max_size] = 200M
      php_admin_value[open_basedir] = "${basedir}:${apacheHttpd}/conf/mime.types:/tmp"
      php_admin_value[session.save_path] = "${varDir}/phpSessions"
      '';
  };
}