lieer: change settings to freeform type
Also add missing options.
This commit is contained in:
parent
4b964d2f7b
commit
514acaebb9
6 changed files with 241 additions and 123 deletions
|
@ -1,69 +0,0 @@
|
||||||
{ 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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -23,32 +23,233 @@ let
|
||||||
map (name: "accounts.email.accounts.${name}.notmuch.enable = true;")
|
map (name: "accounts.email.accounts.${name}.notmuch.enable = true;")
|
||||||
missingNotmuchAccounts;
|
missingNotmuchAccounts;
|
||||||
|
|
||||||
|
settingsFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
configFile = account: {
|
configFile = account: {
|
||||||
name = "${account.maildir.absPath}/.gmailieer.json";
|
name = "${account.maildir.absPath}/.gmailieer.json";
|
||||||
value = {
|
value.source = settingsFormat.generate "lieer-${account.address}.json"
|
||||||
text = builtins.toJSON {
|
({ account = account.address; } // account.lieer.settings);
|
||||||
inherit (account.lieer) timeout;
|
};
|
||||||
account = account.address;
|
|
||||||
replace_slash_with_dot = account.lieer.replaceSlashWithDot;
|
settingsOpts = {
|
||||||
drop_non_existing_label = account.lieer.dropNonExistingLabels;
|
drop_non_existing_label = mkOption {
|
||||||
ignore_tags = account.lieer.ignoreTagsLocal;
|
type = types.bool;
|
||||||
ignore_remote_labels = account.lieer.ignoreTagsRemote;
|
default = false;
|
||||||
} + "\n";
|
description = ''
|
||||||
|
Allow missing labels on the Gmail side to be dropped.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
file_extension = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "";
|
||||||
|
example = "mbox";
|
||||||
|
description = ''
|
||||||
|
Extension to include in local file names, which can be useful
|
||||||
|
for indexing with third-party programs.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ignore_empty_history = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Work around a Gmail API quirk where an empty change history
|
||||||
|
is sometimes returned.
|
||||||
|
</para><para>
|
||||||
|
See this
|
||||||
|
<link xlink:href="https://github.com/gauteh/lieer/issues/120">GitHub issue</link>
|
||||||
|
for more details.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ignore_remote_labels = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [
|
||||||
|
"CATEGORY_FORUMS"
|
||||||
|
"CATEGORY_PROMOTIONS"
|
||||||
|
"CATEGORY_UPDATES"
|
||||||
|
"CATEGORY_SOCIAL"
|
||||||
|
"CATEGORY_PERSONAL"
|
||||||
|
];
|
||||||
|
description = ''
|
||||||
|
Set Gmail labels to ignore when syncing from remote labels to
|
||||||
|
local tags (before translations).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ignore_tags = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Set labels to ignore when syncing from local tags to
|
||||||
|
remote labels (after translations).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
local_trash_tag = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "trash";
|
||||||
|
description = ''
|
||||||
|
Local tag to which the remote Gmail 'TRASH' label is translated.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
remove_local_messages = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Remove local messages that have been deleted on the remote.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
replace_slash_with_dot = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Replace '/' with '.' in Gmail labels.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
timeout = mkOption {
|
||||||
|
type = types.ints.unsigned;
|
||||||
|
default = 600;
|
||||||
|
description = ''
|
||||||
|
HTTP timeout in seconds. 0 means forever or system timeout.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
syncOpts = {
|
||||||
|
enable = mkEnableOption "lieer synchronization service";
|
||||||
|
|
||||||
|
frequency = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "*:0/5";
|
||||||
|
description = ''
|
||||||
|
How often to synchronize the account.
|
||||||
|
</para><para>
|
||||||
|
This value is passed to the systemd timer configuration as the
|
||||||
|
onCalendar option. See
|
||||||
|
<citerefentry>
|
||||||
|
<refentrytitle>systemd.time</refentrytitle>
|
||||||
|
<manvolnum>7</manvolnum>
|
||||||
|
</citerefentry>
|
||||||
|
for more information about the format.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
lieerOpts = {
|
||||||
|
enable = mkEnableOption "lieer Gmail synchronization for notmuch";
|
||||||
|
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = types.submodule {
|
||||||
|
freeformType = settingsFormat.type;
|
||||||
|
options = settingsOpts;
|
||||||
|
};
|
||||||
|
default = { };
|
||||||
|
description = ''
|
||||||
|
Settings which are applied to <filename>.gmailieer.json</filename>
|
||||||
|
for the account.
|
||||||
|
</para><para>
|
||||||
|
See the <link xlink:href="https://github.com/gauteh/lieer/">lieer manual</link>
|
||||||
|
for documentation of settings not explicitly covered by this module.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
sync = syncOpts;
|
||||||
|
};
|
||||||
|
|
||||||
|
lieerModule = types.submodule {
|
||||||
|
imports = [
|
||||||
|
(mkRenamedOptionModule [ "lieer" "dropNonExistingLabels" ] [
|
||||||
|
"lieer"
|
||||||
|
"settings"
|
||||||
|
"drop_non_existing_label"
|
||||||
|
])
|
||||||
|
(mkRenamedOptionModule [ "lieer" "ignoreTagsRemote" ] [
|
||||||
|
"lieer"
|
||||||
|
"settings"
|
||||||
|
"ignore_remote_labels"
|
||||||
|
])
|
||||||
|
(mkRenamedOptionModule [ "lieer" "ignoreTagsLocal" ] [
|
||||||
|
"lieer"
|
||||||
|
"settings"
|
||||||
|
"ignore_tags"
|
||||||
|
])
|
||||||
|
(mkRenamedOptionModule [ "lieer" "timeout" ] [
|
||||||
|
"lieer"
|
||||||
|
"settings"
|
||||||
|
"timeout"
|
||||||
|
])
|
||||||
|
(mkRenamedOptionModule [ "lieer" "replaceSlashWithDot" ] [
|
||||||
|
"lieer"
|
||||||
|
"settings"
|
||||||
|
"replace_slash_with_dot"
|
||||||
|
])
|
||||||
|
];
|
||||||
|
|
||||||
|
options = {
|
||||||
|
lieer = lieerOpts;
|
||||||
|
|
||||||
|
warnings = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
internal = true;
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
renamedOptions = account:
|
||||||
|
let prefix = [ "accounts" "email" "accounts" account.name "lieer" ];
|
||||||
|
in [
|
||||||
|
(mkRenamedOptionModule (prefix ++ [ "dropNonExistingLabels" ])
|
||||||
|
(prefix ++ [ "settings" "drop_non_existing_label" ]))
|
||||||
|
(mkRenamedOptionModule (prefix ++ [ "ignoreTagsRemote" ])
|
||||||
|
(prefix ++ [ "settings" "ignore_remote_labels" ]))
|
||||||
|
(mkRenamedOptionModule (prefix ++ [ "ignoreTagsLocal" ])
|
||||||
|
(prefix ++ [ "settings" "ignore_tags" ]))
|
||||||
|
(mkRenamedOptionModule (prefix ++ [ "timeout" ])
|
||||||
|
(prefix ++ [ "settings" "timeout" ]))
|
||||||
|
(mkRenamedOptionModule (prefix ++ [ "replaceSlashWithDot" ])
|
||||||
|
(prefix ++ [ "settings" "replace_slash_with_dot" ]))
|
||||||
|
];
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ maintainers.tadfisher ];
|
meta.maintainers = [ maintainers.tadfisher ];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
programs.lieer.enable =
|
programs.lieer = {
|
||||||
mkEnableOption "lieer Gmail synchronization for notmuch";
|
enable = mkEnableOption "lieer Gmail synchronization for notmuch";
|
||||||
|
|
||||||
accounts.email.accounts = mkOption {
|
package = mkOption {
|
||||||
type = with types; attrsOf (submodule (import ./lieer-accounts.nix));
|
type = types.package;
|
||||||
|
default = pkgs.gmailieer;
|
||||||
|
defaultText = "pkgs.gmailieer";
|
||||||
|
description = ''
|
||||||
|
lieer package to use.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
accounts.email.accounts =
|
||||||
|
mkOption { type = with types; attrsOf lieerModule; };
|
||||||
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
(mkIf (missingNotmuchAccounts != [ ]) {
|
(mkIf (missingNotmuchAccounts != [ ]) {
|
||||||
warnings = [''
|
warnings = [''
|
||||||
|
@ -82,7 +283,9 @@ in {
|
||||||
'';
|
'';
|
||||||
}];
|
}];
|
||||||
|
|
||||||
home.packages = [ pkgs.gmailieer ];
|
warnings = flatten (map (account: account.warnings) lieerAccounts);
|
||||||
|
|
||||||
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
# Notmuch should ignore non-mail files created by lieer.
|
# Notmuch should ignore non-mail files created by lieer.
|
||||||
programs.notmuch.new.ignore = [ "/.*[.](json|lock|bak)$/" ];
|
programs.notmuch.new.ignore = [ "/.*[.](json|lock|bak)$/" ];
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
{ lib, ... }:
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
{
|
|
||||||
options.lieer.sync = {
|
|
||||||
enable = mkEnableOption "lieer synchronization service";
|
|
||||||
|
|
||||||
frequency = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "*:0/5";
|
|
||||||
description = ''
|
|
||||||
How often to synchronize the account.
|
|
||||||
</para><para>
|
|
||||||
This value is passed to the systemd timer configuration as the
|
|
||||||
onCalendar option. See
|
|
||||||
<citerefentry>
|
|
||||||
<refentrytitle>systemd.time</refentrytitle>
|
|
||||||
<manvolnum>7</manvolnum>
|
|
||||||
</citerefentry>
|
|
||||||
for more information about the format.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -51,15 +51,9 @@ let
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ maintainers.tadfisher ];
|
meta.maintainers = [ maintainers.tadfisher ];
|
||||||
|
|
||||||
options = {
|
options.services.lieer.enable =
|
||||||
services.lieer.enable =
|
|
||||||
mkEnableOption "lieer Gmail synchronization service";
|
mkEnableOption "lieer Gmail synchronization service";
|
||||||
|
|
||||||
accounts.email.accounts = mkOption {
|
|
||||||
type = with types; attrsOf (submodule (import ./lieer-accounts.nix));
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
assertions = [
|
assertions = [
|
||||||
(lib.hm.assertions.assertPlatform "services.lieer" pkgs
|
(lib.hm.assertions.assertPlatform "services.lieer" pkgs
|
||||||
|
|
|
@ -1 +1,18 @@
|
||||||
{"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}
|
{
|
||||||
|
"account": "hm@example.com",
|
||||||
|
"drop_non_existing_label": false,
|
||||||
|
"file_extension": "",
|
||||||
|
"ignore_empty_history": false,
|
||||||
|
"ignore_remote_labels": [
|
||||||
|
"CATEGORY_FORUMS",
|
||||||
|
"CATEGORY_PROMOTIONS",
|
||||||
|
"CATEGORY_UPDATES",
|
||||||
|
"CATEGORY_SOCIAL",
|
||||||
|
"CATEGORY_PERSONAL"
|
||||||
|
],
|
||||||
|
"ignore_tags": [],
|
||||||
|
"local_trash_tag": "trash",
|
||||||
|
"remove_local_messages": true,
|
||||||
|
"replace_slash_with_dot": false,
|
||||||
|
"timeout": 600
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ with lib;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
programs.lieer.enable = true;
|
programs.lieer.enable = true;
|
||||||
|
programs.lieer.package = pkgs.writeScriptBin "dummy-gmailieer" "";
|
||||||
|
|
||||||
accounts.email.accounts."hm@example.com" = {
|
accounts.email.accounts."hm@example.com" = {
|
||||||
flavor = "gmail.com";
|
flavor = "gmail.com";
|
||||||
|
@ -14,14 +15,11 @@ with lib;
|
||||||
notmuch.enable = true;
|
notmuch.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
nixpkgs.overlays = [
|
|
||||||
(self: super: { gmailieer = pkgs.writeScriptBin "dummy-gmailieer" ""; })
|
|
||||||
];
|
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileExists home-files/Mail/hm@example.com/.gmailieer.json
|
assertFileExists home-files/Mail/hm@example.com/.gmailieer.json
|
||||||
assertFileContent home-files/Mail/hm@example.com/.gmailieer.json \
|
assertFileContent home-files/Mail/hm@example.com/.gmailieer.json ${
|
||||||
${./lieer-expected.json}
|
./lieer-expected.json
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue