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'.
This commit is contained in:
parent
0056a5aea1
commit
60a939bd01
|
@ -389,6 +389,7 @@ in
|
||||||
(import ../programs/alot-accounts.nix pkgs)
|
(import ../programs/alot-accounts.nix pkgs)
|
||||||
(import ../programs/astroid-accounts.nix)
|
(import ../programs/astroid-accounts.nix)
|
||||||
(import ../programs/getmail-accounts.nix)
|
(import ../programs/getmail-accounts.nix)
|
||||||
|
(import ../programs/lieer-accounts.nix)
|
||||||
(import ../programs/mbsync-accounts.nix)
|
(import ../programs/mbsync-accounts.nix)
|
||||||
(import ../programs/msmtp-accounts.nix)
|
(import ../programs/msmtp-accounts.nix)
|
||||||
(import ../programs/neomutt-accounts.nix)
|
(import ../programs/neomutt-accounts.nix)
|
||||||
|
|
|
@ -1366,6 +1366,13 @@ in
|
||||||
https://rycee.gitlab.io/home-manager/#sec-install-nixos-module
|
https://rycee.gitlab.io/home-manager/#sec-install-nixos-module
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2020-03-07T14:12:50+00:00";
|
||||||
|
message = ''
|
||||||
|
A new module is available: 'programs.lieer'.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ let
|
||||||
(loadModule ./programs/htop.nix { })
|
(loadModule ./programs/htop.nix { })
|
||||||
(loadModule ./programs/info.nix { })
|
(loadModule ./programs/info.nix { })
|
||||||
(loadModule ./programs/irssi.nix { })
|
(loadModule ./programs/irssi.nix { })
|
||||||
|
(loadModule ./programs/lieer.nix { })
|
||||||
(loadModule ./programs/jq.nix { })
|
(loadModule ./programs/jq.nix { })
|
||||||
(loadModule ./programs/kakoune.nix { })
|
(loadModule ./programs/kakoune.nix { })
|
||||||
(loadModule ./programs/keychain.nix { })
|
(loadModule ./programs/keychain.nix { })
|
||||||
|
|
69
modules/programs/lieer-accounts.nix
Normal file
69
modules/programs/lieer-accounts.nix
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
options.lieer = {
|
||||||
|
enable = mkEnableOption "lieer Gmail synchronization for notmuch";
|
||||||
|
|
||||||
|
timeout = mkOption {
|
||||||
|
type = types.ints.unsigned;
|
||||||
|
default = 0;
|
||||||
|
description = ''
|
||||||
|
HTTP timeout in seconds. 0 means forever or system timeout.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
replaceSlashWithDot = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Replace '/' with '.' in Gmail labels.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
dropNonExistingLabels = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Allow missing labels on the Gmail side to be dropped.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ignoreTagsLocal = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Set custom tags to ignore when syncing from local to
|
||||||
|
remote (after translations).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ignoreTagsRemote = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [
|
||||||
|
"CATEGORY_FORUMS"
|
||||||
|
"CATEGORY_PROMOTIONS"
|
||||||
|
"CATEGORY_UPDATES"
|
||||||
|
"CATEGORY_SOCIAL"
|
||||||
|
"CATEGORY_PERSONAL"
|
||||||
|
];
|
||||||
|
description = ''
|
||||||
|
Set custom tags to ignore when syncing from remote to
|
||||||
|
local (before translations).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
notmuchSetupWarning = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Warn if Notmuch is not also enabled for this account.
|
||||||
|
</para><para>
|
||||||
|
This can safely be disabled if <command>notmuch init</command>
|
||||||
|
has been used to configure this account outside of Home
|
||||||
|
Manager.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
89
modules/programs/lieer.nix
Normal file
89
modules/programs/lieer.nix
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ import nmt {
|
||||||
./modules/programs/fish
|
./modules/programs/fish
|
||||||
./modules/programs/git
|
./modules/programs/git
|
||||||
./modules/programs/gpg
|
./modules/programs/gpg
|
||||||
|
./modules/programs/lieer
|
||||||
./modules/programs/mbsync
|
./modules/programs/mbsync
|
||||||
./modules/programs/neomutt
|
./modules/programs/neomutt
|
||||||
./modules/programs/newsboat
|
./modules/programs/newsboat
|
||||||
|
|
1
tests/modules/programs/lieer/default.nix
Normal file
1
tests/modules/programs/lieer/default.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{ lieer = ./lieer.nix; }
|
1
tests/modules/programs/lieer/lieer-expected.json
Normal file
1
tests/modules/programs/lieer/lieer-expected.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"account":"hm@example.com","drop_non_existing_label":false,"ignore_remote_labels":["CATEGORY_FORUMS","CATEGORY_PROMOTIONS","CATEGORY_UPDATES","CATEGORY_SOCIAL","CATEGORY_PERSONAL"],"ignore_tags":[],"replace_slash_with_dot":false,"timeout":0}
|
22
tests/modules/programs/lieer/lieer.nix
Normal file
22
tests/modules/programs/lieer/lieer.nix
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
|
config = {
|
||||||
|
home.username = "hm-user";
|
||||||
|
home.homeDirectory = "/home/hm-user";
|
||||||
|
|
||||||
|
programs.lieer.enable = true;
|
||||||
|
|
||||||
|
accounts.email.accounts = { "hm@example.com".lieer.enable = true; };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists home-files/Mail/hm@example.com/.gmailieer.json
|
||||||
|
assertFileContent home-files/Mail/hm@example.com/.gmailieer.json \
|
||||||
|
${./lieer-expected.json}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue