From 1251ef424ac876518c35eec2ffbd020571712446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Fri, 19 Apr 2024 11:38:48 +0200 Subject: [PATCH 1/3] himalaya: improve service --- modules/programs/himalaya.nix | 53 +++++++++++++---------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 2d216c3dc..04a277019 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -130,16 +130,6 @@ in { Extra environment variables to be exported in the service. ''; }; - - settings.account = lib.mkOption { - type = with lib.types; nullOr str; - default = null; - example = "personal"; - description = '' - Name of the account the watcher should be started for. - If no account is given, the default one is used. - ''; - }; }; accounts.email.accounts = lib.mkOption { @@ -171,31 +161,26 @@ in { globalConfig = compactAttrs himalaya.settings; allConfig = globalConfig // { accounts = accountsConfig; }; in tomlFormat.generate "himalaya-config.toml" allConfig; - systemd.user.services = let - inherit (config.services.himalaya-watch) enable environment settings; - optionalArg = key: - if (key ? settings && !isNull settings."${key}") then - [ "--${key} ${settings."${key}"}" ] - else - [ ]; - in { - himalaya-watch = lib.mkIf enable { - Unit = { - Description = "Email client Himalaya CLI envelopes watcher service"; - After = [ "network.target" ]; - }; - Install = { WantedBy = [ "default.target" ]; }; - Service = { - ExecStart = lib.concatStringsSep " " - ([ "${himalaya.package}/bin/himalaya" "envelopes" "watch" ] - ++ optionalArg "account"); - ExecSearchPath = "/bin"; - Environment = - lib.mapAttrsToList (key: val: "${key}=${val}") environment; - Restart = "always"; - RestartSec = 10; + + systemd.user.services = + let inherit (config.services.himalaya-watch) enable environment; + in { + "himalaya-watch@" = lib.mkIf enable { + Unit = { + Description = "Email client Himalaya CLI envelopes watcher service"; + After = [ "network.target" ]; + }; + Install = { WantedBy = [ "default.target" ]; }; + Service = { + ExecStart = + "${himalaya.package}/bin/himalaya envelopes watch --account %I"; + ExecSearchPath = "/bin"; + Environment = + lib.mapAttrsToList (key: val: "${key}=${val}") environment; + Restart = "always"; + RestartSec = 10; + }; }; }; - }; }; } From ed33f985da01933b118bec3cefd462b2a8c44d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Fri, 19 Apr 2024 11:56:54 +0200 Subject: [PATCH 2/3] himalaya: make use of lib.getExe --- modules/programs/himalaya.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 04a277019..563de0a53 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -82,7 +82,7 @@ let sendmailConfig = lib.optionalAttrs (isNull account.smtp && !isNull account.msmtp) { sender = "sendmail"; - sendmail.cmd = "${pkgs.msmtp}/bin/msmtp"; + sendmail.cmd = lib.getExe pkgs.msmtp; }; config = lib.attrsets.mergeAttrsList [ @@ -173,7 +173,7 @@ in { Install = { WantedBy = [ "default.target" ]; }; Service = { ExecStart = - "${himalaya.package}/bin/himalaya envelopes watch --account %I"; + "${lib.getExe himalaya.package} envelopes watch --account %I"; ExecSearchPath = "/bin"; Environment = lib.mapAttrsToList (key: val: "${key}=${val}") environment; From 357c1fdbd982a284b6b4d66201473258c980a52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 20 Apr 2024 09:49:20 +0200 Subject: [PATCH 3/3] himalaya: add xdg desktop entry --- modules/programs/himalaya.nix | 60 +++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 563de0a53..54e82972f 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -154,32 +154,44 @@ in { config = lib.mkIf himalaya.enable { home.packages = [ himalaya.package ]; - xdg.configFile."himalaya/config.toml".source = let - enabledAccounts = lib.filterAttrs (_: account: account.himalaya.enable) - config.accounts.email.accounts; - accountsConfig = lib.mapAttrs mkAccountConfig enabledAccounts; - globalConfig = compactAttrs himalaya.settings; - allConfig = globalConfig // { accounts = accountsConfig; }; - in tomlFormat.generate "himalaya-config.toml" allConfig; + xdg = { + configFile."himalaya/config.toml".source = let + enabledAccounts = lib.filterAttrs (_: account: account.himalaya.enable) + config.accounts.email.accounts; + accountsConfig = lib.mapAttrs mkAccountConfig enabledAccounts; + globalConfig = compactAttrs himalaya.settings; + allConfig = globalConfig // { accounts = accountsConfig; }; + in tomlFormat.generate "himalaya-config.toml" allConfig; - systemd.user.services = + desktopEntries.himalaya = lib.mkIf pkgs.stdenv.hostPlatform.isLinux { + type = "Application"; + name = "himalaya"; + genericName = "Email Client"; + comment = "CLI to manage emails"; + terminal = true; + exec = "himalaya %u"; + categories = [ "Network" ]; + mimeType = [ "x-scheme-handler/mailto" "message/rfc822" ]; + settings = { Keywords = "email"; }; + }; + }; + + systemd.user.services."himalaya-watch@" = let inherit (config.services.himalaya-watch) enable environment; - in { - "himalaya-watch@" = lib.mkIf enable { - Unit = { - Description = "Email client Himalaya CLI envelopes watcher service"; - After = [ "network.target" ]; - }; - Install = { WantedBy = [ "default.target" ]; }; - Service = { - ExecStart = - "${lib.getExe himalaya.package} envelopes watch --account %I"; - ExecSearchPath = "/bin"; - Environment = - lib.mapAttrsToList (key: val: "${key}=${val}") environment; - Restart = "always"; - RestartSec = 10; - }; + in lib.mkIf enable { + Unit = { + Description = "Email client Himalaya CLI envelopes watcher service"; + After = [ "network.target" ]; + }; + Install = { WantedBy = [ "default.target" ]; }; + Service = { + ExecStart = + "${lib.getExe himalaya.package} envelopes watch --account %I"; + ExecSearchPath = "/bin"; + Environment = + lib.mapAttrsToList (key: val: "${key}=${val}") environment; + Restart = "always"; + RestartSec = 10; }; }; };