Skip to content

Commit

Permalink
himalaya: add module
Browse files Browse the repository at this point in the history
A very simple TUI mail client.
  • Loading branch information
ambroisie authored Jun 26, 2021
1 parent 8eee5f5 commit 8d3b273
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion modules/accounts/email.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 7 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
'';
}
];
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { })
Expand Down
100 changes: 100 additions & 0 deletions modules/programs/himalaya.nix
Original file line number Diff line number Diff line change
@@ -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 <command>himalaya</command> mail client.
'';
};

settings = mkOption {
type = tomlFormat.type;
default = { };
example = lib.literalExample ''
{
default-page-size = 50;
}
'';
description = ''
Global <command>himalaya</command> 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 <command>himalaya</command>
account configuration.
'';
};
};
});
};
};

config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];

xdg.configFile."himalaya/config.toml".source =
tomlFormat.generate "himalaya-config.toml" himalayaConfig;
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/modules/programs/himalaya/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ himalaya = ./himalaya.nix; }
18 changes: 18 additions & 0 deletions tests/modules/programs/himalaya/himalaya-expected.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
downloads-dir = "/data/download"
name = ""

["hm@example.com"]
default = true
default-page-size = 50
email = "[email protected]"
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
38 changes: 38 additions & 0 deletions tests/modules/programs/himalaya/himalaya.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ config, lib, pkgs, ... }:

with lib;

{
imports = [ ../../accounts/email-test-accounts.nix ];

config = {
accounts.email.accounts = {
"[email protected]" = {
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
}
'';
};
}

0 comments on commit 8d3b273

Please sign in to comment.