My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/infra/libkookie/modules/workstation/mail/core/isync.nix

32 lines
1.1 KiB

{ 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
'';
}