NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.45k stars 13.65k forks source link

firefox-wayland cannot be started if it is already running #87895

Closed evils closed 3 years ago

evils commented 4 years ago

Describe the bug running firefox when firefox is already open fails

To Reproduce Steps to reproduce the behavior:

  1. nix-env -iA nixpkgs.firefox-wayland (in a wayland environment, in my case, sway)
  2. firefox or xdg-open https://nixos.org

Expected behavior firefox to open

Screenshots 2020-05-15T17:11:45,386625390+02:00

Additional context this didn't help
i suspect firefox isn't listening on dbus

Notify maintainers @andir

Metadata

doesn't seem particularly relevant ``` - system: `"x86_64-linux"` - host os: `Linux 5.7.0-rc4, NixOS, 20.09.git.989228702ef (Nightingale)` - multi-user?: `yes` - sandbox: `yes` - version: `nix-env (Nix) 2.3.4` - channels(root): `""` - channels(evils): `"nixos-20.09pre225673.8ba41a1e149, nixos-stable-20.03.1866.a7c70f2e10b, nixos-unstable-small-20.09pre225882.e4d710b1c94, nixpkgs-20.09pre225882.e4d710b1c94"` - nixpkgs: `/home/evils/.nix-defexpr/channels/nixpkgs` ```

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: firefox-wayland
# a list of nixos modules affected by the problem
module:
evils commented 4 years ago

@colemickens on IRC had some inconclusive notes

andir commented 4 years ago

That is basically what that package is doing.

On Fri, May 15, 2020, 5:46 PM evils notifications@github.com wrote:

@colemickens https://github.com/colemickens on IRC mentioned pkgs.firefox + the env var MOZ_USE_WAYLAND should be the only wayland specific stuff applied to firefox https://logs.nix.samueldr.com/nixos/2020-05-15#3463749

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NixOS/nixpkgs/issues/87895#issuecomment-629327737, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE365DX64QIHLTSHZZ74RTRRVPVPANCNFSM4NBVIYZQ .

evils commented 4 years ago

@andir are you sure about that? i'm finding neither MOZ_ENABLE_WAYLAND or MOZ_DBUS_REMOTE in pkgs/application/networking/browsers/firefox neither do i see it in the generated firefox.desktop file or the wrapper that is $out/bin/firefox

andir commented 4 years ago

https://github.com/NixOS/nixpkgs/blob/99efa7c85c8835127c1c65d69665f74f5aaf1a03/pkgs/applications/networking/browsers/firefox/wrapper.nix#L127-L129 Is equivalent to setting MOZ_ENABLE_WAYLAND and predates it. We still can't use the one you mentioned in the wrapper as the esr version we ship doesn't support that yet. Would love to know why @colemickens thinks the GDK backend selection is wrong and we should not do it. Last time I read the firefox source it was equivalent.

colemickens commented 4 years ago

Source, a sort of nebulous knowledge from having attentively watched and dogfooded this space for 18+ months, and https://github.com/swaywm/sway/wiki/Running-programs-natively-under-wayland. (It's a bit of a meme almost that GDK_BACKEND should not be manually set. It has more to do with what other apps are affected, and it does matter for the wrapper because firefox does launch other things)

From a quick look: (I want to look more later but I keep getting distracted)

IMO people are better off not using firefox-wayland and setting MOZ_ENABLE_WAYLAND for their session. I was actually a bit taken aback to realize people are still having all of these issues. Simply using firefox or latest.firefox-nightly-bin and MOZ_ENABLE_WAYLAND=1 has been working well for me for sometime, with none of the sessions issues that seem to be reported with firefox-wayland, or the same issues from users that report setting GDK_BACKEND (both in and out of nixpkgs).

evils commented 4 years ago

with a firefox session started like this:
nix-shell '<nixpkgs>' -p firefox --pure --command 'env MOZ_ENABLE_WAYLAND=1 firefox' the following works from my usual environment xdg-open https://nixos.org

with the same package started from my usual environment plus that variable, that fails

env ``` ALACRITTY_LOG=/tmp/Alacritty-22696.log COLORTERM=truecolor DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-67smSI607J,guid=0049bbe944c04317e73e8b195ebda5ca DESKTOP_SESSION=sway DISPLAY=:1 EDITOR=vim GDMSESSION=sway GIO_EXTRA_MODULES=/nix/store/cc8pvf99h9hzr2cswk5nc9msni73mlxr-dconf-0.36.0-lib/lib/gio/modules GTK_PATH=/home/evils/.nix-profile/lib/gtk-2.0:/home/evils/.nix-profile/lib/gtk-3.0:/etc/profiles/per-user/evils/lib/gtk-2.0:/etc/profiles/per-user/evils/lib/gtk-3.0:/nix/var/nix/profiles/default/lib/gtk-2.0:/nix/var/nix/profiles/default/lib/gtk-3.0:/run/current-system/sw/lib/gtk-2.0:/run/current-system/sw/lib/gtk-3.0 HOME=/home/evils I3SOCK=/run/user/1000/sway-ipc.1000.2359.sock INFOPATH=/home/evils/.nix-profile/info:/home/evils/.nix-profile/share/info:/etc/profiles/per-user/evils/info:/etc/profiles/per-user/evils/share/info:/nix/var/nix/profiles/default/info:/nix/var/nix/profiles/default/share/info:/run/current-system/sw/info:/run/current-system/sw/share/info KDEDIRS=/home/evils/.nix-profile:/etc/profiles/per-user/evils:/nix/var/nix/profiles/default:/run/current-system/sw LANG=en_US.UTF-8 LIBEXEC_PATH=/home/evils/.nix-profile/lib/libexec:/etc/profiles/per-user/evils/lib/libexec:/nix/var/nix/profiles/default/lib/libexec:/run/current-system/sw/lib/libexec LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive LOGNAME=evils MOZ_PLUGIN_PATH=/home/evils/.nix-profile/lib/mozilla/plugins:/etc/profiles/per-user/evils/lib/mozilla/plugins:/nix/var/nix/profiles/default/lib/mozilla/plugins:/run/current-system/sw/lib/mozilla/plugins NIXPKGS_CONFIG=/etc/nix/nixpkgs-config.nix NIX_DEBUG_INFO_DIRS=/run/current-system/sw/lib/debug NIX_PATH=/home/evils/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels NIX_PROFILES=/run/current-system/sw /nix/var/nix/profiles/default /etc/profiles/per-user/evils /home/evils/.nix-profile NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/evils NO_AT_BRIDGE=1 OLDPWD=/home/evils PAGER=less -R PATH=/nix/store/91pi7fp76531z8ciiqy2c24px56v96ms-swaybg-1.0/bin:/run/wrappers/bin:/home/evils/.nix-profile/bin:/etc/profiles/per-user/evils/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin PWD=/home/evils QTWEBKIT_PLUGIN_PATH=/home/evils/.nix-profile/lib/mozilla/plugins/:/etc/profiles/per-user/evils/lib/mozilla/plugins/:/nix/var/nix/profiles/default/lib/mozilla/plugins/:/run/current-system/sw/lib/mozilla/plugins/ QT_PLUGIN_PATH=/home/evils/.nix-profile/lib/qt4/plugins:/home/evils/.nix-profile/lib/kde4/plugins:/etc/profiles/per-user/evils/lib/qt4/plugins:/etc/profiles/per-user/evils/lib/kde4/plugins:/nix/var/nix/profiles/default/lib/qt4/plugins:/nix/var/nix/profiles/default/lib/kde4/plugins:/run/current-system/sw/lib/qt4/plugins:/run/current-system/sw/lib/kde4/plugins SHELL=/run/current-system/sw/bin/zsh SHLVL=2 SSH_ASKPASS=/nix/store/h3anpb6fmbg8xg899sxpqini1xyh7gpq-x11-ssh-askpass-1.2.4.1/libexec/x11-ssh-askpass STRIGI_PLUGIN_PATH=/home/evils/.nix-profile/lib/strigi/:/etc/profiles/per-user/evils/lib/strigi/:/nix/var/nix/profiles/default/lib/strigi/:/run/current-system/sw/lib/strigi/ SWAYSOCK=/run/user/1000/sway-ipc.1000.2359.sock TERM=alacritty TERMINFO_DIRS=/home/evils/.nix-profile/share/terminfo:/etc/profiles/per-user/evils/share/terminfo:/nix/var/nix/profiles/default/share/terminfo:/run/current-system/sw/share/terminfo TZDIR=/etc/zoneinfo USER=evils WAYLAND_DISPLAY=wayland-0 XCURSOR_PATH=/home/evils/.icons:/home/evils/.local/share/icons:/home/evils/.nix-profile/share/icons:/home/evils/.nix-profile/share/pixmaps:/etc/profiles/per-user/evils/share/icons:/etc/profiles/per-user/evils/share/pixmaps:/nix/var/nix/profiles/default/share/icons:/nix/var/nix/profiles/default/share/pixmaps:/run/current-system/sw/share/icons:/run/current-system/sw/share/pixmaps XCURSOR_SIZE=24 XDG_CONFIG_DIRS=/etc/xdg:/home/evils/.nix-profile/etc/xdg:/etc/profiles/per-user/evils/etc/xdg:/nix/var/nix/profiles/default/etc/xdg:/run/current-system/sw/etc/xdg XDG_DATA_DIRS=/home/evils/.nix-profile/share:/etc/profiles/per-user/evils/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/evils XDG_RUNTIME_DIR=/run/user/1000 XDG_SEAT=seat0 XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 XDG_SESSION_CLASS=user XDG_SESSION_DESKTOP=sway XDG_SESSION_ID=2 XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0 XDG_SESSION_TYPE=wayland XDG_VTNR=8 _=/run/current-system/sw/bin/env _SWAY_WRAPPER_ALREADY_EXECUTED=1 __ETC_PROFILE_DONE=1 __NIXOS_SET_ENVIRONMENT_DONE=1 GPG_TTY=/dev/pts/5 ZSH=/nix/store/2y5kdx29qqah78i193az5n3ba3l25b44-oh-my-zsh-2020-05-11/share/oh-my-zsh LESS=-R LC_CTYPE=en_US.UTF-8 LSCOLORS=Gxfxcxdxbxegedabagacad LS_COLORS= NIX_PAGER=cat ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE=fg=8 ```
andir commented 4 years ago

Source, a sort of nebulous knowledge from having attentively watched and dogfooded this space for 18+ months, and https://github.com/swaywm/sway/wiki/Running-programs-natively-under-wayland. (It's a bit of a meme almost that GDK_BACKEND should not be manually set. It has more to do with what other apps are affected, and it does matter for the wrapper because firefox does launch other things) Interesting how things change over time. I still remember that it was proposed to set that for the entire wayland session... I never had issues with it tho..

From a quick look: (I want to look more later but I keep getting distracted)

* `GDK_BACKEND` should not be set
* `MOZ_ENABLE_WAYLAND` should be set
* we should look at if libglvnd is actually needed, and if so, if it's specific to the Wayland build

The wrapper has grown to some monster that it shouldn't be.. There is so much stuff in there that probably only a few people use and some features that aren't even working anymore.

IMO people are better off not using firefox-wayland and setting MOZ_ENABLE_WAYLAND for their session. I was actually a bit taken aback to realize people are still having all of these issues.

Then we just have to flip the variable in the wrapper? I still believe we want a wayland compatible version so users do not have to think about adding that to their environment and can just pick that package instead.

Simply using firefox or latest.firefox-nightly-bin and MOZ_ENABLE_WAYLAND=1 has been working well for me for sometime, with none of the sessions issues that seem to be reported with firefox-wayland, or the same issues from users that report setting GDK_BACKEND (both in and out of nixpkgs).

This was the first time I heard of that issue. I guess GH not pining maintainers (and users not really being able to tag packages) doesn't help with that either.

andir commented 4 years ago

with the same package started from my usual environment plus that variable, that fails

What does fail mean in this case? I have no xdg-open on my machine and firefox doesn't have access to access anything but it's profile.

evils commented 4 years ago

What does fail mean in this case?

it produces the popup shown in the original bug report comment at the top here

evils commented 4 years ago

with a firefox session started like this: nix-shell '<nixpkgs>' -p firefox --pure --command 'env MOZ_ENABLE_WAYLAND=1 firefox'

oh joy, no audio

evils commented 4 years ago

with a firefox session started like this: nix-shell '<nixpkgs>' -p firefox --pure --command 'env MOZ_ENABLE_WAYLAND=1 firefox'

by the fact i'm getting https://github.com/swaywm/wlroots/issues/1595 i'm fairly sure this resulted in an X11 firefox session

edit as to not pile on notifications: nix-shell '<nixpkgs>' -p firefox-wayland --pure --command 'firefox' yields (firefox:3489): Gtk-WARNING **: 21:31:59.004: cannot open display: :1

colemickens commented 4 years ago

@andir Yes, I do agree with everything you said. I think I was/am getting a bit lost on this one and what the exact cause of issue is.

@evils if you're ever confused, pkill Xwayland is a good way to quickly check to see what exactly is running on X.

FlorianFranzen commented 4 years ago

This bug is still an issue with firefox-wayland on 20.03, even if I update the wrapper to set MOZ_ENABLE_WAYLAND=1 instead. Setting MOZ_DBUS_REMOTE=1 also does not change that.

I know this use to work, before updating to the latest stable (e.g. under 19.09 or 20.03pre), but I have not figured out what the underlying issue actually is.

And libglvnd is needed to have GL support in Firefox (see your about:supportpage for details).

I tried to triage the issues with pure nix-shell environments as suggest, but all attempts failed so far, as I was not able to get firefox-wayland to run in wayland mode at all from inside a pure shell.

evils commented 3 years ago

i'm still getting this with firefox-wayland version 81 running on sway 1.5

colemickens commented 3 years ago

I literally have never ever seen this message, even when using Nightly. I don't know how else to help.

On Thu, Sep 24, 2020, 12:05 evils notifications@github.com wrote:

i'm still getting this with firefox-wayland version 81 running on sway 1.5

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NixOS/nixpkgs/issues/87895#issuecomment-698531827, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACP25F6XKTOOLTBVZVCUNTSHOJ73ANCNFSM4NBVIYZQ .

FlorianFranzen commented 3 years ago

@colemickens: Maybe you could be so kind and post a minimal config you are using or at least show us what environment variables you use to get it working. It would also be important to know if you use firefox or firefox-wayland.

evils commented 3 years ago

fwiw, in an attempt to recreate my issue, i made a minimal setup that doesn't have this issue

minimal config, works ``` { config, pkgs, ... }: { virtualisation.memorySize = 2048; environment.systemPackages = with pkgs; [ firefox-wayland ]; services.xserver = { enable = true; layout = "dvorak,us"; xkbVariant = "dvorak"; xkbOptions = "grp:shifts_toggle,lv3:ralt_switch,compose:ralt"; displayManager.defaultSession = "sway"; }; programs = { sway = { enable = true; extraPackages = with pkgs; [ # defining something here removes the defaults? # legacy dmenu xwayland # wayland native swaylock swayidle bemenu alacritty ]; }; }; users.users.evils = { isNormalUser = true; extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. password = "insecure"; }; system.stateVersion = "21.03"; # Did you read the comment? } ```

build with nix-build nixos --arg configuration ./configuration.nix -A vmWithBootLoader in a local checkout of nixos-unstable running xdg-open https://nixos.org twice results in 2 open tabs in firefox

i haven't been able to log in when building the vm based on my actual config (password incorrect, even if i reuse the above user config verbatim)

colemickens commented 3 years ago

The first comment in https://github.com/NixOS/nixpkgs/pull/84233 should include everything relevant to my firefox setup, though most of that is only required for the pipewire functionality.

I use pkgs.firefox with MOZ_ENABLE_WAYLAND=1 and that's about it.

@evils you don't disable Xwayland, by chance, do you?

evils commented 3 years ago

i don't think i'm disabling Xwayland,
i've got vlc running, and other Xwayland stuff

maybe relevant, i've got firefox installed via nix-env

FlorianFranzen commented 3 years ago

@evils: There are various ways nix-env might cause you to run an outdated or modified version of Firefox, especially if you do not update your nix-env with every channel/flake update.

On my end, after updating to 20.09, the issue is gone again, so as far as I am concerned this can be closed as fixed.

evils commented 3 years ago

this issue is gone for me early october i tried installing firefox-wayland via systemPackages in configuration.nix but that didn't help since then i've switched from i think firefox-wayland 82.0.0 installed via nix-env to 83 installed via systemPackages from nixos-unstable (and had a long overdue reboot) and it now works for me as well i'm not immediately seeing an obvious change to the package to explain this though...

Coda-Coda commented 3 years ago

I was having a related issue, where links clicked in vscodium were causing the same issue. After some pain here was my solution in the end in case it helps anyone:

Relevant parts of home.nix (see home-manager)

let
  myFirefox = (firefox.overrideAttrs (_: { desktopItem =
    makeDesktopItem {
          name = "firefox";
          exec = "env MOZ_ENABLE_WAYLAND=1 MOZ_DBUS_REMOTE=1 firefox %u";
          icon = "firefox";
          comment = "";
          desktopName = "Firefox";
          genericName = "Web Browser";
          categories = "Network;WebBrowser;";
          mimeType = lib.concatStringsSep ";" [
            "text/html"
            "text/xml"
            "application/xhtml+xml"
            "application/vnd.mozilla.xul+xml"
            "x-scheme-handler/http"
            "x-scheme-handler/https"
            "x-scheme-handler/ftp"
          ];
        };
    }));
in
{
  home.packages = with pkgs; [
    myFirefox
  ];
    xdg.mimeApps.enable = true;
    xdg.mimeApps.defaultApplications = 
  {
    # Add other defaults here too
    "text/html" = [ "firefox.desktop" ];
    "text/xml" = [ "firefox.desktop" ];
    "application/xhtml+xml" = [ "firefox.desktop" ];
    "application/vnd.mozilla.xul+xml" = [ "firefox.desktop" ];
    "x-scheme-handler/http" = [ "firefox.desktop" ];
    "x-scheme-handler/https" = [ "firefox.desktop" ];
    "x-scheme-handler/ftp" = [ "firefox.desktop" ];
  };
}
JohannesRudolph commented 3 years ago

@Coda-Coda thanks so much for your suggested fix, I can confirm this fixed it for me.

Though this appears to use pkgs.firefox instead of pkgs.firefox-wayland as a base now?

Anyhow, I think this issue should be reopened, something's wrong about the firefox-wayland package. I had firefox-wayland installed via configuration.nix and could still observe the original issue as reported by @evils

colemickens commented 3 years ago

There isn't. The only thing firefox-wayland does is set MOZ_ENABLE_WAYLAND (hence why it does not matter that the above solution uses pkgs.firefox since it also sets that env var).

The relevant part is likely the MOZ_DBUS_REMOTE. See: https://mastransky.wordpress.com/2020/03/16/wayland-x11-how-to-run-firefox-in-mixed-environment/

Coda-Coda commented 3 years ago

@JohannesRudolph I’m glad you found it useful. Yes my fix does use pkgs.firefox now, I’m not sure if firefox-wayland has any important changes that my solution misses out on but I just see @colemickens has said there is nothing else extra firefox-wayland does.

I agree that further discussion and perhaps re-opening the issue would help.

Perhaps firefox-wayland should use MOZ_DBUS_REMOTE if it doesn’t already?