From 8d3b273afef0e6c3d6d6e4239c9c9d79b1ab6ed7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 27 Jun 2021 00:29:42 +0200 Subject: [PATCH] himalaya: add module A very simple TUI mail client. --- .github/CODEOWNERS | 3 + modules/accounts/email.nix | 5 +- modules/misc/news.nix | 7 ++ modules/modules.nix | 1 + modules/programs/himalaya.nix | 100 ++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/himalaya/default.nix | 1 + .../programs/himalaya/himalaya-expected.toml | 18 ++++ tests/modules/programs/himalaya/himalaya.nix | 38 +++++++ 9 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 modules/programs/himalaya.nix create mode 100644 tests/modules/programs/himalaya/default.nix create mode 100644 tests/modules/programs/himalaya/himalaya-expected.toml create mode 100644 tests/modules/programs/himalaya/himalaya.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b487576f7..6ff2a0976 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -84,6 +84,9 @@ /modules/programs/go.nix @rvolosatovs +/modules/programs/himalaya.nix @ambroisie +/tests/modules/programs/himalaya @ambroisie + /modules/programs/home-manager.nix @rycee /modules/programs/htop.nix @bjpbakker diff --git a/modules/accounts/email.nix b/modules/accounts/email.nix index 1e7aff946..f92201495 100644 --- a/modules/accounts/email.nix +++ b/modules/accounts/email.nix @@ -332,7 +332,10 @@ let (mkIf (config.flavor == "gmail.com") { userName = mkDefault config.address; - imap = { host = "imap.gmail.com"; }; + imap = { + host = "imap.gmail.com"; + port = 993; + }; smtp = { host = "smtp.gmail.com"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 0446bd4b6..6e88b6246 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2111,6 +2111,13 @@ in A new module is available: 'i18n.inputMethod'. ''; } + + { + time = "2021-06-22T14:43:53+00:00"; + message = '' + A new module is available: 'programs.himalaya'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 99d5f5490..30e7fecdd 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -78,6 +78,7 @@ let (loadModule ./programs/gnome-terminal.nix { }) (loadModule ./programs/go.nix { }) (loadModule ./programs/gpg.nix { }) + (loadModule ./programs/himalaya.nix { }) (loadModule ./programs/home-manager.nix { }) (loadModule ./programs/htop.nix { }) (loadModule ./programs/i3status.nix { }) diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix new file mode 100644 index 000000000..d7b6d31cc --- /dev/null +++ b/modules/programs/himalaya.nix @@ -0,0 +1,100 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.programs.himalaya; + + enabledAccounts = + lib.filterAttrs (_: a: a.himalaya.enable) (config.accounts.email.accounts); + + tomlFormat = pkgs.formats.toml { }; + + himalayaConfig = let + toHimalayaConfig = account: + { + email = account.address; + name = account.realName; + default = account.primary; + + # FIXME: does not support disabling TLS altogether + # NOTE: does not accept sequence of strings for password commands + imap-login = account.userName; + imap-passwd-cmd = lib.escapeShellArgs account.passwordCommand; + imap-host = account.imap.host; + imap-port = account.imap.port; + imap-starttls = account.imap.tls.useStartTls; + + smtp-login = account.userName; + smtp-passwd-cmd = lib.escapeShellArgs account.passwordCommand; + smtp-host = account.smtp.host; + smtp-port = account.smtp.port; + smtp-starttls = account.imap.tls.useStartTls; + } // (lib.optionalAttrs (account.signature.showSignature == "append") { + # FIXME: signature cannot be attached + signature = account.signature.text; + }) // account.himalaya.settings; + in { + # NOTE: will not start without this configured, but each account overrides it + name = ""; + } // cfg.settings // (lib.mapAttrs (_: toHimalayaConfig) enabledAccounts); +in { + meta.maintainers = with lib.hm.maintainers; [ ambroisie ]; + + options = with lib; { + programs.himalaya = { + enable = mkEnableOption "himalaya mail client"; + + package = mkOption { + type = types.package; + default = pkgs.himalaya; + defaultText = literalExample "pkgs.himalaya"; + description = '' + Package providing the himalaya mail client. + ''; + }; + + settings = mkOption { + type = tomlFormat.type; + default = { }; + example = lib.literalExample '' + { + default-page-size = 50; + } + ''; + description = '' + Global himalaya configuration values. + ''; + }; + }; + + accounts.email.accounts = mkOption { + type = with types; + attrsOf (submodule { + options.himalaya = { + enable = mkEnableOption '' + the himalaya mail client for this account + ''; + + settings = mkOption { + type = tomlFormat.type; + default = { }; + example = lib.literalExample '' + { + default-page-size = 50; + } + ''; + description = '' + Extra settings to add to this himalaya + account configuration. + ''; + }; + }; + }); + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."himalaya/config.toml".source = + tomlFormat.generate "himalaya-config.toml" himalayaConfig; + }; +} diff --git a/tests/default.nix b/tests/default.nix index bdf0771bb..1c3892e4f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -53,6 +53,7 @@ import nmt { ./modules/programs/gh ./modules/programs/git ./modules/programs/gpg + ./modules/programs/himalaya ./modules/programs/htop ./modules/programs/i3status ./modules/programs/irsii diff --git a/tests/modules/programs/himalaya/default.nix b/tests/modules/programs/himalaya/default.nix new file mode 100644 index 000000000..54c3978d8 --- /dev/null +++ b/tests/modules/programs/himalaya/default.nix @@ -0,0 +1 @@ +{ himalaya = ./himalaya.nix; } diff --git a/tests/modules/programs/himalaya/himalaya-expected.toml b/tests/modules/programs/himalaya/himalaya-expected.toml new file mode 100644 index 000000000..db94d42a8 --- /dev/null +++ b/tests/modules/programs/himalaya/himalaya-expected.toml @@ -0,0 +1,18 @@ +downloads-dir = "/data/download" +name = "" + +["hm@example.com"] +default = true +default-page-size = 50 +email = "hm@example.com" +imap-host = "imap.example.com" +imap-login = "home.manager" +imap-passwd-cmd = "'password-command'" +imap-port = 995 +imap-starttls = false +name = "H. M. Test" +smtp-host = "smtp.example.com" +smtp-login = "home.manager" +smtp-passwd-cmd = "'password-command'" +smtp-port = 465 +smtp-starttls = false diff --git a/tests/modules/programs/himalaya/himalaya.nix b/tests/modules/programs/himalaya/himalaya.nix new file mode 100644 index 000000000..ce5385d14 --- /dev/null +++ b/tests/modules/programs/himalaya/himalaya.nix @@ -0,0 +1,38 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + himalaya = { + enable = true; + + settings = { default-page-size = 50; }; + }; + + imap.port = 995; + smtp.port = 465; + }; + }; + + programs.himalaya = { + enable = true; + settings = { downloads-dir = "/data/download"; }; + }; + + nixpkgs.overlays = + [ (self: super: { himalaya = pkgs.writeScriptBin "dummy-alot" ""; }) ]; + + nmt.script = '' + assertFileExists home-files/.config/himalaya/config.toml + assertFileContent home-files/.config/himalaya/config.toml ${ + ./himalaya-expected.toml + } + ''; + }; +} +