aboutsummaryrefslogblamecommitdiff
path: root/virtual/packages/roundcubemail.nix
blob: 1aa2d877eca702481767d10cfdbf0a63f247f135 (plain) (tree)













































































































                                                                                                                
{ lib, checkEnv, writeText, stdenv, fetchurl }:
let
  roundcubemail = let
    plugins = {};
  in rec {
    varDir = "/var/lib/roundcubemail";
    # FIXME: initial sync
    activationScript = {
      deps = [ "wrappers" ];
      text = ''
        install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
          ${varDir}/cache
        install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
      '';
    };
    config =
      # FIXME: LOG_DESTINATION syslog?
      assert checkEnv "NIXOPS_ROUNDCUBEMAIL_PSQL_URL";
      assert checkEnv "NIXOPS_ROUNDCUBEMAIL_SECRET";
      writeText "config.php" ''
      <?php
        $config['db_dsnw'] = '${builtins.getEnv "NIXOPS_ROUNDCUBEMAIL_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['imap_cache'] = 'db';
        $config['messages_cache'] = 'db';

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

        $config['des_key'] = '${builtins.getEnv "NIXOPS_ROUNDCUBEMAIL_SECRET"}';

        $config['plugins'] = array();

        $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'] = 'stdout';
        $config['temp_dir'] = '${varDir}/cache';
        $config['debug_level'] = 1;
      '';
    webRoot = stdenv.mkDerivation rec {
      version = "1.3.8";
      name = "roundcubemail-${version}";
      src= fetchurl {
        url = "https://github.com/roundcube/roundcubemail/releases/download/${version}/${name}-complete.tar.gz";
        sha256 = "018djad7ygfl9c9f2l2j42qkg31ml3hs2f01f0dk361zckwk77n4";
      };
      buildPhase = ''
        sed -i \
          -e "s|RCUBE_INSTALL_PATH . 'temp.*|'${varDir}/cache';|" \
          config/defaults.inc.php
      '';
      installPhase = ''
        cp -a . $out
        ln -s ${config} $out/config/config.inc.php
        ${builtins.concatStringsSep "\n" (
          lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/plugins/${name}") plugins
        )}
      '';
    };
    apache = {
      user = "wwwrun";
      group = "wwwrun";
      modules = [ "proxy_fcgi" ];
      vhostConf = ''
      Alias /roundcube "${webRoot}"
      <Directory "${webRoot}">
          DirectoryIndex index.php
          AllowOverride All
          Options FollowSymlinks
          Require all granted

          <FilesMatch "\.php$">
            SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
          </FilesMatch>
        </Directory>
        '';
    };
    phpFpm = rec {
      basedir = builtins.concatStringsSep ":" (
        [ webRoot config varDir ]
        ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
      socket = "/var/run/phpfpm/roundcubemail.sock";
      pool = ''
        listen = ${socket}
        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[open_basedir] = "${basedir}:/tmp"
        php_admin_value[session.save_path] = "${varDir}/phpSessions"
        '';
    };
  };
in 
  roundcubemail