diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index b487576f7293..6ff2a09768bd 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 1e7aff94611b..f92201495812 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 0446bd4b663b..6e88b6246673 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 99d5f5490b47..30e7fecddefa 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 000000000000..d7b6d31ccd01
--- /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 bdf0771bbcd9..1c3892e4f423 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 000000000000..54c3978d8a49
--- /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 000000000000..db94d42a8a20
--- /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 000000000000..ce5385d14e9a
--- /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
+ }
+ '';
+ };
+}
+