diff options
author | Tad Fisher <tadfisher@gmail.com> | 2020-02-20 23:19:30 -0800 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2020-03-07 15:13:15 +0100 |
commit | 60a939bd01dc66d1cbdc85a3f6dc78e4ca092537 (patch) | |
tree | 92cd0a59b63113dde5f49ba1a2ec11e26eef366d /modules/programs/lieer.nix | |
parent | 0056a5aea1a7b68bdacb7b829c325a1d4a3c4259 (diff) |
programs.lieer: add module
Add 'programs.lieer', a tool for synchronizing a Gmail account with a
local maildir and notmuch database. Per-account configuration lives in
'accounts.email.accounts.<name>.lieer'.
Diffstat (limited to 'modules/programs/lieer.nix')
-rw-r--r-- | modules/programs/lieer.nix | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/modules/programs/lieer.nix b/modules/programs/lieer.nix new file mode 100644 index 00000000000..c04786dbb59 --- /dev/null +++ b/modules/programs/lieer.nix @@ -0,0 +1,89 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.lieer; + + lieerAccounts = + filter (a: a.lieer.enable) (attrValues config.accounts.email.accounts); + + nonGmailAccounts = + map (a: a.name) (filter (a: a.flavor != "gmail.com") lieerAccounts); + + nonGmailConfigHelp = + map (name: ''accounts.email.accounts.${name}.flavor = "gmail.com";'') + nonGmailAccounts; + + missingNotmuchAccounts = map (a: a.name) + (filter (a: !a.notmuch.enable && a.lieer.notmuchSetupWarning) + lieerAccounts); + + notmuchConfigHelp = + map (name: "accounts.email.accounts.${name}.notmuch.enable = true;") + missingNotmuchAccounts; + + configFile = account: { + name = "${account.maildir.absPath}/.gmailieer.json"; + value = { + text = builtins.toJSON { + inherit (account.lieer) timeout; + account = account.address; + replace_slash_with_dot = account.lieer.replaceSlashWithDot; + drop_non_existing_label = account.lieer.dropNonExistingLabels; + ignore_tags = account.lieer.ignoreTagsLocal; + ignore_remote_labels = account.lieer.ignoreTagsRemote; + } + "\n"; + }; + }; + +in { + meta.maintainers = [ maintainers.tadfisher ]; + + options = { + programs.lieer.enable = + mkEnableOption "lieer Gmail synchronization for notmuch"; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf (missingNotmuchAccounts != [ ]) { + warnings = ['' + lieer is enabled for the following email accounts, but notmuch is not: + + ${concatStringsSep "\n " missingNotmuchAccounts} + + Notmuch can be enabled with: + + ${concatStringsSep "\n " notmuchConfigHelp} + + If you have configured notmuch outside of Home Manager, you can suppress this + warning with: + + programs.lieer.notmuchSetupWarning = false; + '']; + }) + + { + assertions = [{ + assertion = nonGmailAccounts == [ ]; + message = '' + lieer is enabled for non-Gmail accounts: + + ${concatStringsSep "\n " nonGmailAccounts} + + If these accounts are actually Gmail accounts, you can + fix this error with: + + ${concatStringsSep "\n " nonGmailConfigHelp} + ''; + }]; + + home.packages = [ pkgs.gmailieer ]; + + # Notmuch should ignore non-mail files created by lieer. + programs.notmuch.new.ignore = [ "/.*[.](json|lock|bak)$/" ]; + + home.file = listToAttrs (map configFile lieerAccounts); + } + ]); +} |