Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox extension that uses native messaging does not work #47340

Open
mickours opened this issue Sep 25, 2018 · 25 comments · May be fixed by #303562
Open

Firefox extension that uses native messaging does not work #47340

mickours opened this issue Sep 25, 2018 · 25 comments · May be fixed by #303562
Labels
0.kind: bug Something is broken

Comments

@mickours
Copy link
Contributor

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:
#33748 (comment)

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
Copy link
Contributor Author

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
Copy link
Member

jtojnar commented Sep 25, 2018

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
Copy link
Contributor Author

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
Copy link
Contributor

hedning commented Sep 25, 2018

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
Copy link
Contributor Author

mickours commented Sep 26, 2018

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Member

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

@worldofpeace
Copy link
Contributor

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
Copy link

wakest commented Feb 11, 2020

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
Copy link

stale bot commented Aug 9, 2020

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.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 9, 2020
@milahu
Copy link
Contributor

milahu commented Oct 10, 2021

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 stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 10, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

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

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 16, 2022
@eddyb
Copy link
Contributor

eddyb commented Sep 10, 2022

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)

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 10, 2022
@huantianad
Copy link
Contributor

Is enablePlasmaBrowserIntegration expected to work withlibrewolf?

@pasqui23
Copy link
Contributor

Is enablePlasmaBrowserIntegration expected to work withlibrewolf?

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

@huantianad
Copy link
Contributor

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

@SuperSandro2000
Copy link
Member

I think this commit SuperSandro2000@cb6a879 fixes this. Can someone confirm this?

@SuperSandro2000
Copy link
Member

@K900 @mweinelt what do you think about this?

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

@mickours
Copy link
Contributor Author

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
Copy link
Member

Please test #303562

@mickours
Copy link
Contributor Author

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;

@tomodachi94 tomodachi94 added the 0.kind: bug Something is broken label May 12, 2024
@honza
Copy link
Contributor

honza commented Jun 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.