nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.89k stars 1.8k forks source link

protonmail-bridge #3019

Open DrPyser opened 2 years ago

DrPyser commented 2 years ago

Description

Hi wonderful nixers. Seeking to integrate my protonmail account. Proton provides a smtp bridge service running in the background that takes care of mail encryption/decryption. It supports IMAP.

There's already a nixos package, and no nixos module. See this discussion that suggests a home-manager integration instead to enable per-user email configurations, and integration with existing home-manager-based email config. The post author(https://discourse.nixos.org/u/3699n) suggests a home-manager module config in their last message there:

{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.services.protonmail-bridge;
  #Still need to integrate more closely with the email management capabilities of home-manager
in
{
  ##### interface
  options = {
    services.protonmail-bridge = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable the Bridge.";
      };

      nonInteractive = mkOption {
        type = types.bool;
        default = false;
        description = "Start Bridge entirely noninteractively";
      };

      logLevel = mkOption {
        type = types.enum [ "panic" "fatal" "error" "warn" "info" "debug" "debug-client" "debug-server" ];
        default = "info";
        description = "The log level";
      };

    };
  };

  ##### implementation
  config = mkIf cfg.enable {

    home.packages = [ pkgs.protonmail-bridge ];

    systemd.user.services.protonmail-bridge = {
      Unit = {
        Description = "Protonmail Bridge";
        After = [ "network.target" ];
      };

      Service = {
        Restart = "always";
        ExecStart = "${pkgs.protonmail-bridge}/bin/protonmail-bridge --no-window --log-level ${cfg.logLevel}" + optionalString (cfg.nonInteractive) " --noninteractive";
      };

      Install = {
        WantedBy = [ "default.target" ];
      };
    };
  };
}
stale[bot] commented 2 years ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

JesusMtnez commented 1 year ago

Did you manage to figure out how to handle the certificate trust?

stale[bot] commented 9 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

nick4f42 commented 2 months ago

I was able to get the provided module working with a few tweaks.

If you aren't already signed into the bridge, you'll have to:

  1. systemctl --user stop protonmail-bridge.service
  2. protonmail-bridge --cli and login
  3. systemctl --user start protonmail-bridge.service
tweaked protonmail-bridge.nix
```nix { config, lib, pkgs, ... }: with lib; let cfg = config.services.protonmail-bridge; in { options = { services.protonmail-bridge = { enable = mkOption { type = types.bool; default = false; description = "Whether to enable the Bridge."; }; package = mkOption { type = types.package; default = pkgs.protonmail-bridge; defaultText = literalExpression "pkgs.protonmail-bridge"; description = "The protonmail-bridge package to use."; }; logLevel = mkOption { type = types.enum [ "panic" "fatal" "error" "warn" "info" "debug" ]; default = "info"; description = "The log level"; }; }; }; config = mkIf cfg.enable { home.packages = [ cfg.package ]; systemd.user.services.protonmail-bridge = { Unit = { Description = "Protonmail Bridge"; After = [ "network.target" ]; }; Service = { Restart = "always"; ExecStart = "${cfg.package}/bin/protonmail-bridge --noninteractive --log-level ${cfg.logLevel}"; }; Install = { WantedBy = [ "default.target" ]; }; }; }; } ```

If you're like me and have pass installed but would prefer bridge to use gnome keyring, this was the best solution I could manage:

protonmail-bridge config
```nix services.protonmail-bridge = { enable = true; package = # Ensure pass is not in the PATH. pkgs.runCommand "protonmail-bridge" { bridge = pkgs.protonmail-bridge; nativeBuildInputs = [ pkgs.makeWrapper ]; } '' mkdir -p $out/bin makeWrapper $bridge/bin/protonmail-bridge $out/bin/protonmail-bridge \ --set PATH ${lib.strings.makeBinPath [ pkgs.gnome3.gnome-keyring ]} ''; }; ```
SpiderUnderUrBed commented 2 months ago

+1 I would love to see this in homemanager and one day nixpkgs.

I do use KDE and I do want to know how to set this up using the kde polkit rather than gnomes, if anyone knows how to get it to work with KDE I would like to hear it.