From 4e9efaa68b0be7e19127dad4f0506a9b89e28ef4 Mon Sep 17 00:00:00 2001 From: nakoo <4975021+nakoo@users.noreply.github.com> Date: Fri, 30 May 2025 02:07:27 +0000 Subject: [PATCH] misc: add librewolf native messaging hosts (#7127) --- modules/misc/mozilla-messaging-hosts.nix | 90 ++++++++++++++------ modules/programs/firefox.nix | 11 ++- modules/programs/firefox/mkFirefoxModule.nix | 5 -- modules/programs/floorp.nix | 11 ++- modules/programs/librewolf.nix | 6 ++ 5 files changed, 88 insertions(+), 35 deletions(-) diff --git a/modules/misc/mozilla-messaging-hosts.nix b/modules/misc/mozilla-messaging-hosts.nix index 1692054a..b142f7cb 100644 --- a/modules/misc/mozilla-messaging-hosts.nix +++ b/modules/misc/mozilla-messaging-hosts.nix @@ -23,6 +23,12 @@ let "Library/Application Support/Mozilla/NativeMessagingHosts" else ".mozilla/native-messaging-hosts"; + + librewolfNativeMessagingHostsPath = + if isDarwin then + "Library/Application Support/LibreWolf/NativeMessagingHosts" + else + ".librewolf/native-messaging-hosts"; in { meta.maintainers = with lib.maintainers; [ @@ -49,49 +55,77 @@ in List of Thunderbird native messaging hosts to configure. ''; }; + + librewolfNativeMessagingHosts = lib.mkOption { + internal = true; + type = with lib.types; listOf package; + default = [ ]; + description = '' + List of Librewolf native messaging hosts to configure. + ''; + }; }; config = - lib.mkIf (cfg.firefoxNativeMessagingHosts != [ ] || cfg.thunderbirdNativeMessagingHosts != [ ]) + lib.mkIf + ( + cfg.firefoxNativeMessagingHosts != [ ] + || cfg.thunderbirdNativeMessagingHosts != [ ] + || cfg.librewolfNativeMessagingHosts != [ ] + ) { home.file = - if isDarwin then - let - firefoxNativeMessagingHostsJoined = pkgs.symlinkJoin { - name = "ff-native-messaging-hosts"; - paths = defaultPaths ++ cfg.firefoxNativeMessagingHosts; - }; - thunderbirdNativeMessagingHostsJoined = pkgs.symlinkJoin { - name = "th-native-messaging-hosts"; - paths = defaultPaths ++ cfg.thunderbirdNativeMessagingHosts; - }; - in - { - "${thunderbirdNativeMessagingHostsPath}" = lib.mkIf (cfg.thunderbirdNativeMessagingHosts != [ ]) { - source = "${thunderbirdNativeMessagingHostsJoined}/lib/mozilla/native-messaging-hosts"; + let + mkNmhLink = + { name, nativeMessagingHosts }: + let + packageJoin = pkgs.symlinkJoin { + inherit name; + paths = lib.flatten ( + lib.concatLists [ + defaultPaths + nativeMessagingHosts + ] + ); + }; + in + lib.mkIf (nativeMessagingHosts != [ ]) { + source = "${packageJoin}/lib/mozilla/native-messaging-hosts"; recursive = true; ignorelinks = true; }; + in + if isDarwin then + { + "${thunderbirdNativeMessagingHostsPath}" = mkNmhLink { + name = "th-native-messaging-hosts"; + nativeMessagingHosts = cfg.thunderbirdNativeMessagingHosts; + }; - "${firefoxNativeMessagingHostsPath}" = lib.mkIf (cfg.firefoxNativeMessagingHosts != [ ]) { - source = "${firefoxNativeMessagingHostsJoined}/lib/mozilla/native-messaging-hosts"; - recursive = true; - ignorelinks = true; + "${firefoxNativeMessagingHostsPath}" = mkNmhLink { + name = "ff-native-messaging-hosts"; + nativeMessagingHosts = cfg.firefoxNativeMessagingHosts; + }; + + "${librewolfNativeMessagingHostsPath}" = mkNmhLink { + name = "lw-native-messaging-hosts"; + nativeMessagingHosts = cfg.librewolfNativeMessagingHosts; }; } else - let - nativeMessagingHostsJoined = pkgs.symlinkJoin { + { + "${firefoxNativeMessagingHostsPath}" = mkNmhLink { name = "mozilla-native-messaging-hosts"; # on Linux, the directory is shared between Firefox and Thunderbird; merge both into one - paths = defaultPaths ++ cfg.firefoxNativeMessagingHosts ++ cfg.thunderbirdNativeMessagingHosts; + nativeMessagingHosts = [ + cfg.firefoxNativeMessagingHosts + cfg.thunderbirdNativeMessagingHosts + ]; }; - in - { - "${firefoxNativeMessagingHostsPath}" = { - source = "${nativeMessagingHostsJoined}/lib/mozilla/native-messaging-hosts"; - recursive = true; - ignorelinks = true; + + "${librewolfNativeMessagingHostsPath}" = mkNmhLink { + name = "librewolf-native-messaging-hosts"; + nativeMessagingHosts = cfg.librewolfNativeMessagingHosts; }; }; }; diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 8d473daa..fec23840 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -1,7 +1,9 @@ -{ lib, ... }: +{ lib, config, ... }: let inherit (lib) mkRemovedOptionModule; + cfg = config.programs.firefox; + modulePath = [ "programs" "firefox" @@ -52,4 +54,11 @@ in modulePath ++ [ "enableIcedTea" ] ) "Support for this option has been removed.") ]; + + config = lib.mkIf cfg.enable { + mozilla.firefoxNativeMessagingHosts = + cfg.nativeMessagingHosts + # package configured native messaging hosts (entire browser actually) + ++ (lib.optional (cfg.finalPackage != null) cfg.finalPackage); + }; } diff --git a/modules/programs/firefox/mkFirefoxModule.nix b/modules/programs/firefox/mkFirefoxModule.nix index dc4f823f..6c17adaf 100644 --- a/modules/programs/firefox/mkFirefoxModule.nix +++ b/modules/programs/firefox/mkFirefoxModule.nix @@ -862,11 +862,6 @@ in home.packages = lib.optional (cfg.finalPackage != null) cfg.finalPackage; - mozilla.firefoxNativeMessagingHosts = - cfg.nativeMessagingHosts - # package configured native messaging hosts (entire browser actually) - ++ (lib.optional (cfg.finalPackage != null) cfg.finalPackage); - home.file = mkMerge ( [ { diff --git a/modules/programs/floorp.nix b/modules/programs/floorp.nix index ce1cadf7..50e52d76 100644 --- a/modules/programs/floorp.nix +++ b/modules/programs/floorp.nix @@ -1,10 +1,12 @@ -{ lib, ... }: +{ lib, config, ... }: let modulePath = [ "programs" "floorp" ]; + cfg = config.programs.floorp; + mkFirefoxModule = import ./firefox/mkFirefoxModule.nix; in { @@ -26,4 +28,11 @@ in }; }) ]; + + config = lib.mkIf cfg.enable { + mozilla.firefoxNativeMessagingHosts = + cfg.nativeMessagingHosts + # package configured native messaging hosts (entire browser actually) + ++ (lib.optional (cfg.finalPackage != null) cfg.finalPackage); + }; } diff --git a/modules/programs/librewolf.nix b/modules/programs/librewolf.nix index 161c6f2a..2f0620fb 100644 --- a/modules/programs/librewolf.nix +++ b/modules/programs/librewolf.nix @@ -34,6 +34,7 @@ in description = "LibreWolf is a privacy enhanced Firefox fork."; wrappedPackageName = "librewolf"; unwrappedPackageName = "librewolf-unwrapped"; + visible = true; platforms.linux = { configPath = ".librewolf"; @@ -68,5 +69,10 @@ in home.file.".librewolf/librewolf.overrides.cfg" = lib.mkIf (cfg.settings != { }) { text = mkOverridesFile cfg.settings; }; + + mozilla.librewolfNativeMessagingHosts = + cfg.nativeMessagingHosts + # package configured native messaging hosts (entire browser actually) + ++ (lib.optional (cfg.finalPackage != null) cfg.finalPackage); }; }