diff --git a/modules/misc/news/2025/08/2025-08-13_16-34-57.nix b/modules/misc/news/2025/08/2025-08-13_16-34-57.nix new file mode 100644 index 000000000..f3549f5bf --- /dev/null +++ b/modules/misc/news/2025/08/2025-08-13_16-34-57.nix @@ -0,0 +1,13 @@ +{ pkgs, ... }: +{ + time = "2025-08-13T21:34:57+00:00"; + condition = pkgs.stdenv.hostPlatform.isLinux; + message = '' + A new module is available: 'services.protonmail-bridge'. + + ProtonMail Bridge is a desktop application that runs in the background, + encrypting and decrypting messages as they enter and leave your computer. + It lets you add your ProtonMail account to your favorite email client via + IMAP/SMTP by creating a local email server on your computer. + ''; +} diff --git a/modules/services/protonmail-bridge.nix b/modules/services/protonmail-bridge.nix new file mode 100644 index 000000000..84603d32c --- /dev/null +++ b/modules/services/protonmail-bridge.nix @@ -0,0 +1,71 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.protonmail-bridge; +in +{ + meta.maintainers = with lib.hm.maintainers; [ epixtm ]; + + options.services.protonmail-bridge = { + enable = lib.mkEnableOption "ProtonMail Bridge"; + package = lib.mkPackageOption pkgs "protonmail-bridge" { }; + + extraPackages = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = [ ]; + example = lib.literalExpression "with pkgs; [ pass gnome-keyring ]"; + description = "List of derivations to place in ProtonMail Bridge's service path."; + }; + + logLevel = lib.mkOption { + type = lib.types.nullOr ( + lib.types.enum [ + "panic" + "fatal" + "error" + "warn" + "info" + "debug" + ] + ); + default = null; + description = '' + Log level of the ProtonMail Bridge service. + + If set to null, the service uses its default log level. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.protonmail-bridge" pkgs lib.platforms.linux) + ]; + + home.packages = [ cfg.package ]; + + systemd.user.services.protonmail-bridge = { + Unit = { + Description = "ProtonMail Bridge"; + After = [ "graphical-session.target" ]; + }; + + Service = { + Environment = lib.mkIf (cfg.extraPackages != [ ]) [ "PATH=${lib.makeBinPath cfg.extraPackages}" ]; + ExecStart = + "${lib.getExe cfg.package} --noninteractive" + + lib.optionalString (cfg.logLevel != null) " --log-level ${cfg.logLevel}"; + Restart = "always"; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; + }; +} diff --git a/tests/modules/services/protonmail-bridge/basic-configuration.nix b/tests/modules/services/protonmail-bridge/basic-configuration.nix new file mode 100644 index 000000000..57bd28db1 --- /dev/null +++ b/tests/modules/services/protonmail-bridge/basic-configuration.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: +{ + services.protonmail-bridge = { + enable = true; + package = pkgs.protonmail-bridge-gui; + extraPackages = with pkgs; [ + gnome-keyring + ]; + logLevel = "info"; + }; + + nmt.script = '' + local service="home-files/.config/systemd/user/protonmail-bridge.service" + + assertFileExists $service + assertFileRegex $service 'Environment=PATH=.*gnome-keyring.*' + assertFileRegex $service 'ExecStart=.*/protonmail-bridge-gui --noninteractive --log-level info' + ''; +} diff --git a/tests/modules/services/protonmail-bridge/default.nix b/tests/modules/services/protonmail-bridge/default.nix new file mode 100644 index 000000000..349372b22 --- /dev/null +++ b/tests/modules/services/protonmail-bridge/default.nix @@ -0,0 +1,5 @@ +{ lib, pkgs, ... }: +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + protonmail-bridge-basic-configuration = ./basic-configuration.nix; + protonmail-bridge-empty-settings = ./empty-settings.nix; +} diff --git a/tests/modules/services/protonmail-bridge/empty-settings.nix b/tests/modules/services/protonmail-bridge/empty-settings.nix new file mode 100644 index 000000000..581f8a246 --- /dev/null +++ b/tests/modules/services/protonmail-bridge/empty-settings.nix @@ -0,0 +1,11 @@ +{ + services.protonmail-bridge.enable = true; + + nmt.script = '' + local service="home-files/.config/systemd/user/protonmail-bridge.service" + + assertFileExists $service + assertFileNotRegex $service 'Environment=PATH=.*' + assertFileRegex $service 'ExecStart=.*/protonmail-bridge --noninteractive' + ''; +}