diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-14T11·44+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-12-14T11·44+0000 |
commit | 3f199f96506d2559dd51d8fff629790e057c9149 (patch) | |
tree | 2ffdc8289f70568fa63ed97097d8da04ccaee989 /infra/nixos/mail.nix | |
parent | 83f1b769fb433c1f3be1fe38c8d31910753a6123 (diff) |
chore(nixos): Move NixOS config to infra/nixos
Diffstat (limited to 'infra/nixos/mail.nix')
-rw-r--r-- | infra/nixos/mail.nix | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/infra/nixos/mail.nix b/infra/nixos/mail.nix new file mode 100644 index 000000000000..a9375a1eea4d --- /dev/null +++ b/infra/nixos/mail.nix @@ -0,0 +1,83 @@ +# 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 + + # Tag nix-devel mailing list & discourse: + -inbox +nix-devel -- to:nix-devel@googlegroups.com OR from:nixos1@discoursemail.com + + # 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 + + # Drafts are always read, duh. + -unread -- tag:draft + + # Tag development list + -inbox +aprila-dev -- to:dev@aprila.no OR cc:dev@aprila.no +''; + +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 = [ "timers.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; + }; +} |