aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/modules/workstation/mail/core/isync.nix
blob: a736925058a122cdc87fd94d39a48faa72ff7532 (plain)
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
{ config, pkgs, ... }:

let cfg = config.libkookie.workstation.mail;
in
with pkgs;
{
  serviceConfig.Type = "oneshot";

  script = let
    cfgPath = (cfg.configPath + "/mbsyncrc.nix");
    mbsyncBody = (import cfgPath cfg.mailArchive);
    mbsyncrc = (writeText "mbsyncrc" mbsyncBody);
  in
    ''
      ${sudo}/bin/sudo -u mail-user ${isync}/bin/mbsync -a -V -c ${mbsyncrc}
    '';
  
  # This script loops through the mail archive and changes file
  # permissions and ownership to allow the main user to access them.
  # It then also runs `notmuch new` to update applications.
  #
  # Yes this script could use a single `find` invocation, but
  # personally I've found that to be unclear, and this script running
  # in the background means that speed is not of much concearn.
  postStart = ''
    ${findutils}/bin/find ${cfg.mailArchive} ! -name .mbsyncstate* | xargs chgrp ${cfg.access.group}
    ${findutils}/bin/find ${cfg.mailArchive} -type f | xargs chmod 660
    ${findutils}/bin/find ${cfg.mailArchive} -type d | xargs chmod 770

    ${sudo}/bin/sudo -u ${cfg.access.user} ${notmuch}/bin/notmuch new
  '';
}