diff options
author | Vincent Ambo <mail@tazj.in> | 2018-06-06T14·26+0200 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2018-06-06T14·26+0200 |
commit | 1239f26e8a771b4040e8ebd557de0738b4d7d24a (patch) | |
tree | 1134cc0c0cac7f4867a81f97e03cdb5371e6c79f /mail.nix | |
parent | 969c0071820b29061d4efe3d230831ae5f7c97b3 (diff) |
feat(mail): Import email configuration into Nix
This moves my email configuration into NixOS, including the following features: 1. Replaced the NixOS-builtin offlineimap user service with a custom one that runs notmuch-indexing as part of the systemd unit instead of a postsynchook, which is significantly more reliable. 2. Adds configuration for notmuch and its tagging. 3. Adds configuration for OfflineIMAP & MSMTP. Relevant emacs configuration has also been added to my emacs.d repository.
Diffstat (limited to 'mail.nix')
-rw-r--r-- | mail.nix | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/mail.nix b/mail.nix new file mode 100644 index 000000000000..7fb70f196c19 --- /dev/null +++ b/mail.nix @@ -0,0 +1,73 @@ +# This file configures offlineimap, notmuch and MSMTP. +# +# Some manual configuration is required the first time this is +# applied: +# +# 1. Credential setup. +# 2. Linking of MSMTP config (ln -s /etc/msmtprc ~/.msmtprc) +# 3. Linking of notmuch config (ln -s /etc/notmuch-config ~/.notmuch-config) + +{ config, lib, pkgs, ... }: + +let offlineImapConfig = pkgs.writeText "offlineimaprc" + (builtins.readFile ./dotfiles/offlineimaprc); + +msmtpConfig = pkgs.writeText "msmtprc" + (builtins.readFile ./dotfiles/msmtprc); + +notmuchConfig = pkgs.writeText "notmuch-config" + (builtins.readFile ./dotfiles/notmuch-config); + +tagConfig = pkgs.writeText "notmuch-tags" '' + # Tag emacs-devel mailing list: + -inbox +emacs-devel -- to:emacs-devel@gnu.org OR cc:emacs-devel@gnu.org + + # Filter out Gitlab mails: + -inbox +gitlab -- from:gitlab@aprila.no + + # Tag my own mail (from other devices) as sent: + -inbox +sent -- folder:"aprila/Sende element" OR from:vincent@aprila.no OR from:mail@tazj.in +''; + +notmuchIndex = pkgs.writeShellScriptBin "notmuch-index" '' + echo "Indexing new mails in notmuch" + + # Index new mail + ${pkgs.notmuch}/bin/notmuch new + + # Apply tags + cat ${tagConfig} | ${pkgs.notmuch}/bin/notmuch tag --batch + + echo "Done indexing new mails" +''; +in { + # Enable OfflineIMAP timer & service: + systemd.user.timers.offlineimap = { + description = "OfflineIMAP timer"; + wantedBy = [ "default.target" ]; + + timerConfig = { + Unit = "offlineimap.service"; + OnCalendar = "*:0/2"; # every 2 minutes + Persistent = "true"; # persist timer state after reboots + }; + }; + + systemd.user.services.offlineimap = { + description = "OfflineIMAP service"; + path = with pkgs; [ pass notmuch ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.offlineimap}/bin/offlineimap -u syslog -o -c ${offlineImapConfig}"; + ExecStartPost = "${notmuchIndex}/bin/notmuch-index"; + TimeoutStartSec = "2min"; + }; + }; + + # Link configuration files to /etc/ (from where they will be linked + # further): + environment.etc = { + "msmtprc".source = msmtpConfig; + "notmuch-config".source = notmuchConfig; + }; +} |