NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.65k stars 13.11k forks source link

Firefox extension that uses native messaging does not work #47340

Open mickours opened 5 years ago

mickours commented 5 years ago

I tried for a long time now to make browserpass and gnome-extensions firefox plugins to work in NixOS without success. I find out that these two extensions are using the Native Messaging interface, that is used by Firefox to interact with local applications. So, looking at the Firefox debug console, I get this error:

No such native application com.dannyvankooten.browserpass

It seems that the extension manifest was not found.

I finally find out where it comes from, thanks to this issue #33748. This comment is giving the problem cause and the workaround: https://github.com/NixOS/nixpkgs/issues/33748#issuecomment-356978749

Basically, the problem comes from Firefox looking for a path in /usr/lib/ that does not exist in NixOS and the workaround is to create a link in the user's home with:

mkdir ~/.mozilla/native-messaging-hosts/
ln -s $(nix-build '<nixpkgs>' -A chrome-gnome-shell)/lib/mozilla/native-messaging-hosts/org.gnome.chrome_gnome_shell.json ~/.mozilla/native-messaging-hosts/
ln -s $(nix-build '<nixpkgs>' -A browserpass)/lib/mozilla/native-messaging-hosts/com.dannyvankooten.browserpass.json ~/.mozilla/native-messaging-hosts/

A bug was open in the Firefox side two years ago, but maybe a small patch would do the trick ;)

I'm opening a new issue because the previous one was too specific on browserpass and closed because of another issue with gpg that was fixed.

mickours commented 5 years ago

I'm not sure but it seems that the path where the manifest is looked up is set here.

Does anyone that know the code of Firefox can confirm?

jtojnar commented 5 years ago

You can add something like nixpkgs.config.firefox.enableBrowserpass = true; and nixpkgs.config.firefox.enableGnomeExtensions = true; to your configuration.nix. You can even add arbitrary nmh packages by installing (pkgs.firefox.override { extraNativeMessagingHosts = [ pkgs.gnomeExtensions.gsconnect ]; }).

mickours commented 5 years ago

Sorry if I wasn't clear but this is the problem actually, both options were already set:

nixpkgs.config.firefox.enableBrowserpass = true; 
nixpkgs.config.firefox.enableGnomeExtensions = true; 

But the extensions were not working and Firefox was still complaining that it can't find the extensions with errors like:

No such native application com.dannyvankooten.browserpass
hedning commented 5 years ago

Just to be sure, are you using firefox-bin? That's the upstream build from mozilla and isn't patched to detect the nixpkgs config.

mickours commented 5 years ago

Just to be sure, are you using firefox-bin? That's the upstream build from mozilla and isn't patched to detect the nixpkgs config.

I'm using the firefox package that contains the nix-support folder:

$ realpath $(which firefox)
/nix/store/3d10spgq6fc573ih4wpgjqn7x2iyr8b3-firefox-62.0/bin/firefox
$ l /nix/store/3d10spgq6fc573ih4wpgjqn7x2iyr8b3-firefox-62.0
total 16
dr-xr-xr-x 2 root root 4096  1 janv.  1970 bin
dr-xr-xr-x 3 root root 4096  1 janv.  1970 lib
dr-xr-xr-x 2 root root 4096  1 janv.  1970 nix-support
dr-xr-xr-x 4 root root 4096  1 janv.  1970 share

With NixOS unstable (but the problem is here for a long time now):

$ nixos-version 
19.03pre153158.7df10f388da (Koi)
coreyoconnor commented 5 years ago

See also https://unix.stackexchange.com/questions/437248

I've done some tracing on this: Firefox is not looking in MOZ_SYSTEM_DIR for native messaging hosts. I suspect there was a change related to policies that disabled this.

Documentation is sparse on all fronts. I haven't determined what the correct directory should be. One reference said use share instead of lib. That did not work for me.

A temp workaround that did resolve the issue was to copy the manifest jsons under ~/.mozilla/native-messaging-hosts.

mickours commented 5 years ago

Note that the workaround is not resistant to updates. Here is a better implementation using home-manager:


{
    imports = [
      "${builtins.fetchTarball https://github.com/rycee/home-manager/archive/master.tar.gz}/nixos"
    ];

    nixpkgs.config.firefox.enableBrowserpass = true;
    nixpkgs.config.firefox.enableGnomeExtensions = true;

    home-manager.users.MYUSER = {
        home.file.".mozilla/native-messaging-hosts/com.dannyvankooten.browserpass.json".source = "${pkgs.browserpass}/lib/mozilla/native-messaging-hosts/com.dannyvankooten.browserpass.json";
        home.file.".mozilla/native-messaging-hosts/org.gnome.chrome_gnome_shell.json".source = "${pkgs.chrome-gnome-shell}/lib/mozilla/native-messaging-hosts/org.gnome.chrome_gnome_shell.json";
    };
}
coreyoconnor commented 5 years ago

Nice! Thanks for the tip.

The post-update issue, in my case, was observed as a "error" reported on accessing https://extensions.gnome.org/ .

glasserc commented 5 years ago

I decided to open https://bugzilla.mozilla.org/show_bug.cgi?id=1538954 to surface this discussion within Mozilla because the patch shipped in Nixpkgs only covers the firefox derivation (users of firefox-bin are left out in the cold).

infinisil commented 5 years ago

Oh btw, I added better instructions to browserpass for Nix/NixOS recently, in https://github.com/browserpass/browserpass/pull/308: https://github.com/browserpass/browserpass#configuring-browserpass-on-nixos--for-nix

worldofpeace commented 4 years ago

This came up when I was helping someone on mastodon https://mastodon.social/web/statuses/103631567654364956. We need to get some sort of warning or information about firefox vs firefox-bin, and in particular that the native messaging stuff doesn't work as expected.

wakest commented 4 years ago

thanks @worldofpeace for walking me through that. I was very confused why it wasn't working and had not even thought about checking with a different install of firefox. using the non bin version it now works as expected.

stale[bot] commented 3 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

milahu commented 2 years ago

Basically, the problem comes from Firefox looking for a path in /usr/lib/ that does not exist in NixOS

we could make that path exist ...

I've done some tracing on this: Firefox is not looking in MOZ_SYSTEM_DIR for native messaging hosts. I suspect there was a change related to policies that disabled this.

... or use a ld_preload library to resolve fstat/open syscalls from /usr/lib to $MOZ_SYSTEM_DIR >: D i made something similar (rewrite fstat/open syscalls) here

$ strace firefox 2>&1 | grep /usr/lib 
newfstatat(AT_FDCWD, "/usr/lib", 0x7ffee5d75160, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib32", 0x7ffee5d75160, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/lib64", 0x7ffee5d75160, 0) = -1 ENOENT (No such file or directory)

or use a ld_preload library

edit: no, firefox is statically linked

→ maybe there is a fork of firefox, where either MOZ_SYSTEM_DIR is parsed, or which is dynamically linked, so we can use ld_preload

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

eddyb commented 1 year ago

So I have firefox (not firefox-bin, so this is unrelated to any of that discussion above) from nix-env (I've been meaning to switch to home-manager on this machine too, just didn't get around it) and I was a bit confused regarding the Plasma integration addon.

This seems to have done the job though, so the note on the wiki seems incorrect:

$ ls -l $(dirname $(readlink $(which firefox)))/../lib/mozilla/native-messaging-hosts/
total 0

$ nano ~/.nixpkgs/config.nix 

$ cat ~/.nixpkgs/config.nix
{
  firefox.enablePlasmaBrowserIntegration = true;

  # ... the rest of my `config.nix` file ...
}

$ nix-env -iA nixos.firefox
replacing old 'firefox-103.0.2'
installing 'firefox-103.0.2'
this path will be fetched (0.57 MiB download, 4.82 MiB unpacked):
  /nix/store/6c79h7gb5gvgpd4938yxg2zdffbd3h2j-firefox-103.0.2
copying path '/nix/store/6c79h7gb5gvgpd4938yxg2zdffbd3h2j-firefox-103.0.2' from 'https://cache.nixos.org'...
building '/nix/store/bqgyzgm7xpn5pgd9rnx3w7xrxw0m46ip-user-environment.drv'...

$ ls -l $(dirname $(readlink $(which firefox)))/../lib/mozilla/native-messaging-hosts/
total 9
lrwxrwxrwx 1 root root 152 Jan  1  1970 org.kde.plasma.browser_integration.json -> /nix/store/s718ag183gd8chm757gzy49i1wdh306p-plasma-browser-integration-5.25.4/lib/mozilla/native-messaging-hosts/org.kde.plasma.browser_integration.json

So it seems like ~/.nixpkgs/config.nix plays all the roles of nixpkgs.config but for per-user nix-env - which makes perfect sense, but I wasn't sure until I tried. I assume that it would be easier to just add firefox to my system-wide packages (since then e.g. enablePlasmaBrowserIntegration is already automatically set).

Now to restart Firefox and see if it really works!

EDIT: yupp, finally have Plasma Browser Integration working in Firefox! (I think I only ever had it working in Chromium accidentally because I had that installed system-wide from ages ago, hah)

huantianad commented 1 year ago

Is enablePlasmaBrowserIntegration expected to work withlibrewolf?

pasqui23 commented 10 months ago

Is enablePlasmaBrowserIntegration expected to work withlibrewolf?

Yes, it should just be config.librewolf.enablePlasmaBrowserIntegration=true if it weren't for this bug.

huantianad commented 10 months ago

I managed to get it working on librewolf by overriding the package instead of using the config option, see #233568

SuperSandro2000 commented 10 months ago

I think this commit https://github.com/SuperSandro2000/nixpkgs/commit/cb6a879f145aa8361c959f3d93bf07b5da3b6e53 fixes this. Can someone confirm this?

SuperSandro2000 commented 7 months ago

@K900 @mweinelt what do you think about this?

I think this might be only necessary for users of firefox-bin thought.

mickours commented 3 months ago

FYI the workaround described here was not necessary in anymore in 23.05 but after updating to 23.11 browserpass seems to be broken again. The debug console of the extension shows:

Error: No such native application com.github.browserpass.native

So I've re-enabled the workaround but the native extension name has changed. The new version is:

home.file.".mozilla/native-messaging-hosts/com.github.browserpass.native.json".source = "${pkgs.browserpass}/lib/mozilla/native-messaging-hosts/com.github.browserpass.native.json";
SuperSandro2000 commented 3 months ago

Please test #303562

mickours commented 3 months ago

Sorry. I just tried, and the problem is still there even after restarting firefox. Same error:

Error: No such native application com.github.browserpass.native

I do have in my config:

programs.browserpass.enable = true;
programs.firefox.enable = true;
honza commented 1 month ago

FYI the workaround described here was not necessary in anymore in 23.05 but after updating to 23.11 browserpass seems to be broken again. The debug console of the extension shows:

Error: No such native application com.github.browserpass.native

So I've re-enabled the workaround but the native extension name has changed. The new version is:

home.file.".mozilla/native-messaging-hosts/com.github.browserpass.native.json".source = "${pkgs.browserpass}/lib/mozilla/native-messaging-hosts/com.github.browserpass.native.json";

This works for me.