From 2bbdd930bbd87226c537f414527c9a7b28f2f4ea Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Sat, 2 Nov 2024 19:12:45 -0400 Subject: [PATCH] thunderbird: add native host support Note: the test case uses a firefox native host but it shouldn't matter since they are packaged the same way for both TB and Firefox. --- modules/programs/thunderbird.nix | 49 ++++++++++++++++++- .../programs/thunderbird/thunderbird.nix | 22 ++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/modules/programs/thunderbird.nix b/modules/programs/thunderbird.nix index 84710207ce54..339bcb599cb4 100644 --- a/modules/programs/thunderbird.nix +++ b/modules/programs/thunderbird.nix @@ -136,6 +136,24 @@ let '') prefs)} ${extraPrefs} ''; + + nativeMessagingHostsPath = if isDarwin then + "${cfg.vendorPath}/NativeMessagingHosts" + else + "${cfg.vendorPath}/native-messaging-hosts"; + + nativeMessagingHostsJoined = pkgs.symlinkJoin { + name = "th_native-messaging-hosts"; + paths = [ + # Link a .keep file to keep the directory around + (pkgs.writeTextDir "lib/mozilla/native-messaging-hosts/.keep" "") + # Link package configured native messaging hosts (entire mail app actually) + cfg.package + ] + # Link user configured native messaging hosts + ++ cfg.nativeMessagingHosts; + }; + in { meta.maintainers = with hm.maintainers; [ d-dervishi jkarlson ]; @@ -158,6 +176,29 @@ in { description = "profile version, set null for nix-darwin"; }; + vendorPath = mkOption { + internal = true; + type = with types; nullOr str; + # Thunderbird doesn't look in `Application Support` on macOS for user + # config (in contrast to global settings that are the same for Firefox + # and Thunderbird): + # https://developer.thunderbird.net/add-ons/mailextensions/supported-webextension-api + default = if isDarwin then "Library/Mozilla" else ".mozilla"; + example = ".mozilla"; + description = + "Directory containing the native messaging hosts directory."; + }; + + nativeMessagingHosts = optionalAttrs (cfg.vendorPath != null) (mkOption { + visible = true; + type = types.listOf types.package; + default = [ ]; + description = '' + Additional packages containing native messaging hosts that should be + made available to Thunderbird extensions. + ''; + }); + profiles = mkOption { type = with types; attrsOf (submodule ({ config, name, ... }: { @@ -403,7 +444,13 @@ in { home.file = mkMerge ([{ "${thunderbirdConfigPath}/profiles.ini" = mkIf (cfg.profiles != { }) { text = generators.toINI { } profilesIni; }; - }] ++ flip mapAttrsToList cfg.profiles (name: profile: { + }] ++ optional (cfg.vendorPath != null) { + "${nativeMessagingHostsPath}" = { + source = + "${nativeMessagingHostsJoined}/lib/mozilla/native-messaging-hosts"; + recursive = true; + }; + } ++ flip mapAttrsToList cfg.profiles (name: profile: { "${thunderbirdProfilesPath}/${name}/chrome/userChrome.css" = mkIf (profile.userChrome != "") { text = profile.userChrome; }; diff --git a/tests/modules/programs/thunderbird/thunderbird.nix b/tests/modules/programs/thunderbird/thunderbird.nix index 366f8b045aab..952e48de9068 100644 --- a/tests/modules/programs/thunderbird/thunderbird.nix +++ b/tests/modules/programs/thunderbird/thunderbird.nix @@ -41,6 +41,9 @@ # Disable warning so that platforms' behavior is the same darwinSetupWarning = false; + # Darwin doesn't support wrapped Thunderbird, using unwrapped instead + package = pkgs.thunderbird-unwrapped; + profiles = { first = { isDefault = true; @@ -62,18 +65,31 @@ }; }; + nativeMessagingHosts = with pkgs; + [ + # NOTE: this is not a real Thunderbird native host module but Firefox; no + # native hosts are currently packaged for nixpkgs or elsewhere, so we + # have to improvise. Packaging wise, Firefox and Thunderbird native hosts + # are identical though. Good news is that the test will still pass as + # long as we don't attempt to run the mail client itself with the host. + # (Which we don't.) + browserpass + ]; + settings = { "general.useragent.override" = ""; "privacy.donottrackheader.enabled" = true; }; }; - test.stubs.thunderbird = { }; - nmt.script = let isDarwin = pkgs.stdenv.hostPlatform.isDarwin; configDir = if isDarwin then "Library/Thunderbird" else ".thunderbird"; profilesDir = if isDarwin then "${configDir}/Profiles" else "${configDir}"; + nativeHostsDir = if isDarwin then + "Library/Mozilla/NativeMessagingHosts" + else + ".mozilla/native-messaging-hosts"; platform = if isDarwin then "darwin" else "linux"; in '' assertFileExists home-files/${configDir}/profiles.ini @@ -95,5 +111,7 @@ assertFileExists home-files/${profilesDir}/first/chrome/userContent.css assertFileContent home-files/${profilesDir}/first/chrome/userContent.css \ <(echo "* { color: red !important; }") + + assertFileExists home-files/${nativeHostsDir}/com.github.browserpass.native.json ''; }