NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.35k stars 14.31k forks source link

Screensharing support in Wayland with Chromium/Chrome (tracking issue) #91218

Open jsravn opened 4 years ago

jsravn commented 4 years ago

Describe the bug I'm trying to use the pipewire support in Chromium to do screensharing on Wayland. I have gotten this working on other distros. However on nix, xdg-desktop-portal segfaults. Here is a backtrace:

#0  append_parent_permissions (remote=remote@entry=0x7fe72000fbb0, permission_items=permission_items@entry=0x7fe714006ef0, 
    string_stash=string_stash@entry=0x7fe728aa6688, global=0x0, permission=permission@entry=0x484c07 "r--") at src/screen-cast.c:530
530  if (global->parent_id == 0)
[Current thread is 1 (Thread 0x7fe728aa7700 (LWP 2540))]
warning: File "/nix/store/7w0ixsxzv2y3d6h59cm8vck26988m61g-gcc-9.3.0-lib/lib/libstdc++.so.6.0.28-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load:/nix/store/danv012gh0aakh8xnk2b35vahklz72mk-gcc-9.2.0-lib:/nix/store/a6z7ighixg7gb6krf9k60ylgmahij63x-gcc-9.3.0-lib/lib/libstdc++.so.6.0.28-gdb.py".
To enable execution of this file add
    add-auto-load-safe-path /nix/store/7w0ixsxzv2y3d6h59cm8vck26988m61g-gcc-9.3.0-lib/lib/libstdc++.so.6.0.28-gdb.py
line to your configuration file "/home/james/.gdbinit".
To completely disable this security protection add
    set auto-load safe-path /
line to your configuration file "/home/james/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
    info "(gdb)Auto-loading safe path"
(gdb) bt
#0  append_parent_permissions (remote=remote@entry=0x7fe72000fbb0, permission_items=permission_items@entry=0x7fe714006ef0, 
    string_stash=string_stash@entry=0x7fe728aa6688, global=0x0, permission=permission@entry=0x484c07 "r--") at src/screen-cast.c:530
#1  0x00000000004231ab in append_stream_permissions (remote=remote@entry=0x7fe72000fbb0, permission_items=permission_items@entry=0x7fe714006ef0, 
    string_stash=string_stash@entry=0x7fe728aa6688, streams=streams@entry=0x20e2020) at src/screen-cast.c:571
#2  0x00000000004233ac in open_pipewire_screen_cast_remote (app_id=<optimized out>, streams=streams@entry=0x20e2020, error=error@entry=0x7fe728aa6730)
    at src/screen-cast.c:639
#3  0x00000000004234b5 in handle_open_pipewire_remote (object=0x20d5640, invocation=0x7fe71c0145f0, in_fd_list=<optimized out>, 
    arg_session_handle=<optimized out>, arg_options=<optimized out>) at src/screen-cast.c:935
#4  0x00007fe739a55abd in ffi_call_unix64 () from /nix/store/0nnvvz3n21ripg3p2n88528scw1hgq26-libffi-3.3/lib/../lib64/libffi.so.7
#5  0x00007fe739a5479c in ffi_call_int () from /nix/store/0nnvvz3n21ripg3p2n88528scw1hgq26-libffi-3.3/lib/../lib64/libffi.so.7
#6  0x00007fe739f9c6ec in g_cclosure_marshal_generic () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libgobject-2.0.so.0
#7  0x00007fe739f9bdd4 in g_closure_invoke () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libgobject-2.0.so.0
#8  0x00007fe739fae53e in signal_emit_unlocked_R () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libgobject-2.0.so.0
#9  0x00007fe739fb9358 in g_signal_emitv () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libgobject-2.0.so.0
#10 0x0000000000453360 in _xdp_screen_cast_skeleton_handle_method_call (connection=<optimized out>, sender=<optimized out>, object_path=<optimized out>, 
    interface_name=0x7fe71c017d20 "org.freedesktop.portal.ScreenCast", method_name=0x7fe71c00bd30 "OpenPipeWireRemote", parameters=<optimized out>, 
    invocation=0x7fe71c0145f0, user_data=0x20d5640) at src/xdp-dbus.c:34229
#11 0x00007fe73a1003d0 in dispatch_in_thread_func () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libgio-2.0.so.0
#12 0x00007fe73a09413e in g_task_thread_pool_thread () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libgio-2.0.so.0
#13 0x00007fe739ed8c44 in g_thread_pool_thread_proxy () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libglib-2.0.so.0
#14 0x00007fe739ed83dd in g_thread_proxy () from /nix/store/qajqzmvfaqwvszadx1149pabf9ivr276-glib-2.64.3/lib/libglib-2.0.so.0
#15 0x00007fe739e42edd in start_thread () from /nix/store/c2rlh7xa8fcgg7qz8pl76ipvvb172c6k-glibc-2.30/lib/libpthread.so.0
#16 0x00007fe739d73acf in clone () from /nix/store/c2rlh7xa8fcgg7qz8pl76ipvvb172c6k-glibc-2.30/lib/libc.so.6

To Reproduce Steps to reproduce the behavior:

  1. Enable xdg-desktop-portal-wlr and xdg-desktop-portal.
  2. Go to chrome://flags and enable the pipewire RTC support (only available in unstable currently).
  3. Go to https://mozilla.github.io/webrtc-landing/gum_test.html and try to screenshare.

As I'm on 20.03, I have this module to enable xdg-desktop-portal with debug symbols:

{ config, lib, pkgs, ... }:
with lib;
let xdp = pkgs.enableDebugging pkgs.unstable.xdg-desktop-portal;
in {
  config = {
    systemd.packages = with pkgs; [
      unstable.pipewire
      xdp 
      unstable.xdg-desktop-portal-wlr
    ];
    systemd.user.sockets.pipewire.wantedBy = [ "sockets.target" ];
    services.dbus.packages = with pkgs; [
      xdp
      unstable.xdg-desktop-portal-wlr
    ];
    environment.variables = {
      XDG_DESKTOP_PORTAL_DIR = pkgs.symlinkJoin {
        name = "xdg-portals";
        paths = [ pkgs.unstable.xdg-desktop-portal-wlr ];
      } + "/share/xdg-desktop-portal/portals";
    };
  };
}

If on unstable you can just use the xdg.portal module.

Expected behavior Screen sharing should work.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Notify maintainers

@jtojnar

Metadata

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
jtojnar commented 4 years ago

Is not this the same as https://github.com/NixOS/nixpkgs/issues/89528#issuecomment-640086776? That should have been fixed https://github.com/NixOS/nixpkgs/pull/90039.

But if pkgs.unstable refers to 9480bae3370, that should already have 0.3.6: https://github.com/NixOS/nixpkgs/blob/9480bae3370/pkgs/development/libraries/pipewire/default.nix

jsravn commented 4 years ago

I get the crash w/ 0.3.6 as well. I think 0.3.6 fixed an issue w/ 0.2 client protocol. However I can't even get to that point as xdg-desktop-portal itself is crashing.

jtojnar commented 4 years ago

Could you try https://github.com/NixOS/nixpkgs/pull/88598?

cc @flokli

jsravn commented 4 years ago

@jtojnar It seems to be working w/ 1.7.2! Awesome, thanks!

jsravn commented 4 years ago

On 20.03 (unstable is the nixos unstable channel):

{ stdenv
, fetchFromGitHub
, nixosTests
, substituteAll
, autoreconfHook
, pkgconfig
, libxml2
, glib
, unstable
, fontconfig
, flatpak
, gsettings-desktop-schemas
, acl
, dbus
, fuse
, libportal
, geoclue2
, json-glib
, wrapGAppsHook
}:

stdenv.mkDerivation rec {
  pname = "xdg-desktop-portal";
  version = "1.7.2";

  outputs = [ "out" "installedTests" ];

  src = fetchFromGitHub {
    owner = "flatpak";
    repo = pname;
    rev = version;
    sha256 = "0rkwpsmbn3d3spkzc2zsd50l2r8pp4la390zcpsawaav8w7ql7xm";
  };

  patches = [
    # Hardcode paths used by x-d-p itself.
    (substituteAll {
      src = ./fix-paths.patch;
      inherit flatpak;
    })
  ];

  nativeBuildInputs = [
    autoreconfHook
    pkgconfig
    libxml2
    wrapGAppsHook
  ];

  buildInputs = [
    glib
    unstable.pipewire
    fontconfig
    flatpak
    acl
    dbus
    geoclue2
    fuse
    libportal
    gsettings-desktop-schemas
    json-glib
  ];

  configureFlags = [
    "--enable-installed-tests"
  ];

  makeFlags = [
    "installed_testdir=${placeholder "installedTests"}/libexec/installed-tests/xdg-desktop-portal"
    "installed_test_metadir=${placeholder "installedTests"}/share/installed-tests/xdg-desktop-portal"
  ];

  passthru = {
    tests = {
      installedTests = nixosTests.installed-tests.xdg-desktop-portal;
    };
  };

  meta = with stdenv.lib; {
    description = "Desktop integration portals for sandboxed apps";
    license = licenses.lgpl21;
    maintainers = with maintainers; [ jtojnar ];
    platforms = platforms.linux;
  };
}
flokli commented 4 years ago

@jsravn with https://github.com/NixOS/nixpkgs/pull/88598 merged, I here are my findings:

I used this VM test description:

import ./make-test-python.nix ({ pkgs, ... }: {
  name = "chrome-wayland-screensharing";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ flokli ];
  };

  machine =
    { pkgs, ... }: {

      imports = [ ./common/user-account.nix ];
      nixpkgs.config.allowUnfree = true;

      virtualisation.memorySize = 1024;

      programs.sway.enable = true;

      services.xserver.enable = true; #??
      services.xserver.displayManager.sddm = {
        enable = true;
        autoLogin = {
          enable = true;
          user = "alice";
        };
      };
      services.xserver.displayManager.defaultSession = "sway";

      hardware.pulseaudio.enable = true;
      sound.enable = true;

      xdg.portal = {
        enable = true;
        extraPortals = with pkgs; [ xdg-desktop-portal-wlr ];
        gtkUsePortal = true;
      };

      services.pipewire.enable = true;
      environment.systemPackages = [
        pkgs.google-chrome-beta
        pkgs.chromium
      ];
    };

    testScript = { nodes, ... }: let
      user = nodes.machine.config.users.users.alice;
    in ''
      machine.start()

      with subtest("Wait for sway to boot up"):
          machine.wait_for_file("/run/user/${toString user.uid}/wayland-0.lock")
          machine.sleep(10)
          # alt+return, run `systemctl --user import-environment`
          # Run chrome
          # Go to chrome://flags and enable the pipewire RTC support (only available in unstable currently).
          # Go to https://mozilla.github.io/webrtc-landing/gum_test.html and try to screenshare.
          # for a real NixOS tests, this needs to be tested without having to rely on networking
    '';
})

I manually built the test driver usingnix-build nixos/tests/chrome-wayland.nix -A driver, ran the VM via result/bin/nixos-run-vms and then followed the comments in the script. This obviously still needs some work for a proper test.

My findings:

Error messages otherwise:

machine # [  148.124107] pipewire[3540]: [E][000000148.056183][dbus.c:319 impl_get_connection()] Failed to connect to system bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
machine # [  148.126469] pipewire[3540]: [E][000000148.058780][module-portal.c:782 pipewire__module_init()] Failed to connect to system bus
machine # [  148.128040] pipewire[3540]: [E][000000148.058790][impl-module.c:281 pw_context_load_module()] "/nix/store/q29k6dmcr54sr3s6qbvai42hcrrawpvh-pipewire-0.3.6-lib/lib/pipewire-0.3/libpipewire-module-portal.so": failed to initialize: Cannot allocate memory
machine # [  148.133684] pipewire[3540]: [E][000000148.058853][daemon-config.c:202 pw_daemon_config_run_commands()] could not run command load-module: could not load module "libpipewire-module-portal": Cannot allocate memory
machine # [  148.138694] pipewire[3540]: [E][000000148.058860][main.c:123 main()] failed to run config commands: Cannot allocate memory

This is especially annoying, as pipewire is socket-activated, and needs to be restarted if it has already been before the import-environment was run. We should really do this in a sway NixOS module in a sane way.

Using google-chrome-beta as a client, the daemon doesn't segfault anymore, but it still complains about the protocol:

machine # [  209.423267] pipewire[3798]: [W][000000209.355581][module-rtkit.c:499 idle_func()] could not make thread realtime: No such file or directory
machine # [  209.446129] pipewire[3800]: [E][000000209.378505][bluez5-dbus.c:2022 get_managed_objects_reply()] GetManagedObjects() failed: org.freedesktop.DBus.Error.ServiceUnknown
machine # [  226.724437] pipewire[3798]: [W][000000226.656777][impl-client.c:608 pw_impl_client_update_permissions()] client 0x2161890: invalid global 469835776
machine # [  226.735033] pipewire[3798]: [W][000000226.667615][impl-client.c:608 pw_impl_client_update_permissions()] client 0x2175410: invalid global 469834768
machine # [  260.104445] pipewire[3798]: [W][000000260.036721][impl-client.c:608 pw_impl_client_update_permissions()] client 0x2189190: invalid global 469842528

Using chromium, the daemon doesn't complain about the protocol. I can share the screen, but it's mostly black (I mostly seem to be sharing a mouse cursor moving around a black screen)

We might also need to explicitly enable audio when the pipewire daemon - I saw some complaints in the log, and enabled both pulseaudio and hardware.sound, but I assume hardware.sound only should be sufficient.

jsravn commented 4 years ago

I have this in my sway config:

exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK DBUS_SESSION_BUS_ADDRESS
exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK DBUS_SESSION_BUS_ADDRESS

I don't think there is a way around this - as DISPLAY won't exist until sway starts. Arguably sway itself should be exporting this but it is agnostic of systemd/dbus.

Also - any tips to run the test? I'm trying to run it within sway - I have kvm-intel enabled and libvirtd. The VM boots up but I can only access the ttys - the graphical tty7 just shows a black screen. No errors in the logs. I'm guessing I need some qemu setting...

flokli commented 4 years ago

@jsravn I think the pipewire systemd user service is missing DBUS_SESSION_BUS_ADDRESS here - not sure about why it's not part of the environment of systemd user services… :thinking:

Regarding DISPLAY, WAYLAND_DISPLAY, SWAYSOCK etc.: https://github.com/swaywm/sway/wiki/Systemd-integration provides some suggestions on how this can be done in a less racy way, which should probably put into the Sway module (and abandon the other hacks currently in our Wiki)

betaboon commented 4 years ago

I'm curious. i got it to work with google-chrome easily quite a while ago. i documented that here: https://github.com/colemickens/nixpkgs-wayland/pull/211

jsravn commented 4 years ago

Thanks! I forgot that you need to set XDG_CURRENT_DESKTOP=sway and XDG_SESSION_TYPE=wayland for xdg-desktop-portal-wlr to activate.

terlar commented 4 years ago

Using the tips of @betaboon I got this working as well under GNOME 3.36.3. The only thing needed was to wrap the google-chrome with the older pipewire_0_2. That was by head-ache that I was trying with the latest version of pipewire first.

I revised the derivation a bit: google-chrome-with-pipewire/default.nix

{ makeWrapper, stdenv, google-chrome, pipewire }:

with builtins;

let
  binName = head (filter (n: match "^\\..*" n == null)
    (attrNames (readDir "${google-chrome}/bin")));
  pnameFromName = p: replaceStrings [ "-${p.version}" ] [ "" ] p.name;
in stdenv.mkDerivation {
  pname = "${pnameFromName google-chrome}-with-pipewire";
  inherit (google-chrome) version;

  buildInputs = [ makeWrapper ];
  buildCommand = ''
    makeWrapper \
      "${google-chrome}/bin/${binName}" \
      $out/bin/${binName} \
      --prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [ pipewire ]} \
      --add-flags '--enable-features=WebRTCPipeWireCapturer'
  '';
}

and then use it like this in an overlay:

final: prev:

{
  google-chrome-beta-with-pipewire =
    prev.callPackage ./google-chrome-with-pipewire {
      google-chrome = final.google-chrome-beta;
      pipewire = final.pipewire_0_2;
    };
  google-chrome-dev-with-pipewire =
    prev.callPackage ./google-chrome-with-pipewire {
      google-chrome = final.google-chrome-dev;
      pipewire = final.pipewire_0_2;
    };
}

One interesting thing is that this works with full screen sharing, while it does not seem to work with sharing individual windows, however that works without pipewire, so might have to run with two different instances of chrome to achieve that.

betaboon commented 4 years ago

@terlar i believe xdg-desktop-portal-wlr only supports sharing the full screen and not individual windows atm. i believe sharing individual windows works only for xwayland windows (which you could identify by using xeyes)

flokli commented 4 years ago

It's probably fine to add pipewire_0_2 to google-chrome's library path, like we do for chromium.

stale[bot] commented 3 years ago

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

primeos commented 3 years ago

I guess this can be closed now. With #104504 it worked for me, but I'm not sure if it still works.

The situation will hopefully improve in 2021 with support for PipeWire 0.3:

d4g commented 3 years ago

@primeos if it works for you know, a working config would be nice. I can't really get it to work.

Running unstable, chromium just tells me:

[30080:30080:0112/173510.029650:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.portal.Desktop was not provided by any .service files
[30080:30080:0112/173510.030252:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.portal.Desktop was not provided by any .service files

Chromium wrapper:

#!/bin/sh

dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK DBUS_SESSION_BUS_ADDRESS
systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK DBUS_SESSION_BUS_ADDRESS

chromium --enable-features=UseOzonePlatform --ozone-platform=wayland

according configuration.nix:

  xdg.portal = { 
    enable = true;
    extraPortals = [ pkgs.xdg-desktop-portal-wlr ];
    gtkUsePortal = true;
  };  
  services.pipewire = { 
    enable = true;
  };  

    programs.sway = { 
      enable = true;
      wrapperFeatures = { 
        base = true;
        gtk = true;
      };  
      extraSessionCommands = 
      ''  
        export SDL_VIDEODRIVER=wayland
        export QT_QPA_PLATFORM=wayland
        export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
        export _JAVA_AWT_WM_NONREPARENTING=1
        export SUDO_ASKPASS="${pkgs.ksshaskpass}/bin/ksshaskpass"
        export SSH_ASKPASS="${pkgs.ksshaskpass}/bin/ksshaskpass"
        export XDG_SESSION_TYPE=wayland
        export XDG_CURRENT_DESKTOP=sway
      ''; 
primeos commented 3 years ago

@d4g your config LGTM but you might need xdg-desktop-portal-gtk in xdg.portal.extraPortals. In any case it looks like the assertion in nixos/modules/config/xdg/portal.nix isn't ideal:

      assertions = [
        { assertion = (cfg.gtkUsePortal -> cfg.extraPortals != []);
          message = "Setting xdg.portal.gtkUsePortal to true requires a portal implementation in xdg.portal.extraPortals such as xdg-desktop-portal-gtk or xdg-desktop-portal-kde.";
        }
      ];

Back when I tested this it was just our of curiosity / for fun so my config might not be very useful / ideal but here is the relevant stuff that is still in my /etc/nixos/configuration.nix (I hope that I didn't remove anything after testing):

configuration.nix ```nix # Screen sharing: xdg.portal = { enable = true; extraPortals = with pkgs; [ xdg-desktop-portal-wlr xdg-desktop-portal-gtk ]; gtkUsePortal = true; }; services.pipewire.enable = true; programs.sway = { enable = true; extraPackages = with pkgs; [ # Shouldn't be relevant for screen sharing but just in case: xwayland qt5.qtwayland # ... ]; extraSessionCommands = '' # Screen sharing export XDG_CURRENT_DESKTOP=sway export XDG_SESSION_TYPE=wayland # Other stuff that shouldn't be relevant for screen sharing: export SDL_VIDEODRIVER=wayland export QT_QPA_PLATFORM=wayland # needs qt5.qtwayland in systemPackages export QT_WAYLAND_DISABLE_WINDOWDECORATION=1 # Fix for some Java AWT applications (e.g. Android Studio), # use this if they aren't displayed properly: export _JAVA_AWT_WM_NONREPARENTING=1 # Old: export XKB_DEFAULT_OPTIONS=caps:escape ''; ```

Unfortunately I don't remember how I launched Chromium, but IIRC I only ran systemctl --user import-environment (since it was only for testing purposes) before.

I also gave it another quick try but it might be broken again. I get a slightly different error though:

[16941:16941:0112/210416.016999:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop
[16941:16941:0112/210416.017176:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop
[16976:17017:0112/210416.230554:ERROR:ssl_client_socket_impl.cc(960)] handshake failed; returned -1, SSL error code 1, net_error -218
[16976:17017:0112/210416.230658:ERROR:ssl_client_socket_impl.cc(960)] handshake failed; returned -1, SSL error code 1, net_error -218
[16941:16941:0112/210418.560731:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop
[17023:13:0112/210418.591310:ERROR:client_native_pixmap_dmabuf.cc(252)] Failed to mmap dmabuf: Function not implemented (38)

In any case the GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown might be easy to resolve in case anyone is interested. Could be due to an upstream change in the xdg-desktop-portal package (that provides e.g. share/dbus-1/interfaces/org.freedesktop.portal.ScreenCast.xml) or due to a change in the Nixpkgs package/module.

d4g commented 3 years ago

Thanks @primeos . I check if this works if I add xdg-desktop-portal-gtk. If it doesn't, we should probably reopen the issue as it is not resolved?

Should this change work immediately? Would I need to restart my user session? Should there be anything visibly running as process from the whole desktop portal software packages?

d4g commented 3 years ago

So I applied the changes, logged in again, still no success:


[11577:11577:0113/085406.053075:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.portal.Desktop was not provided by any .service files
[11577:11577:0113/085406.053168:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.portal.Desktop was not provided by any .service files
[11643:11643:0113/085409.411188:ERROR:gl_surface_presentation_helper.cc(259)] GetVSyncParametersIfAvailable() failed for 2 times!

I think we should really only close this issue, after we have a working configuration that is probably documented, or even have a configuration option that will set the appropriate settings where feasible.

d4g commented 3 years ago

I also did a clean reboot.

Error messages on Chromium start:

top.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[3481:3740:0113/091142.591750:ERROR:object_proxy.cc(621)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[3481:3740:0113/091142.593086:ERROR:object_proxy.cc(621)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files

[3576:3576:0113/091147.811782:ERROR:gl_surface_presentation_helper.cc(259)] GetVSyncParametersIfAvailable() failed for 1 times!
[3481:3481:0113/091154.318135:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop
[3481:3481:0113/091154.318170:ERROR:base_capturer_pipewire.cc(517)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop

Also it seems that a restart of the systemd user session is required for the settings to work. Now it seems to me, that the font rendering is completely broken. Probably related to the xdg-desktop-portal:

image

This is in termite.

image

waybar

The font rendering in sway itself is still fine. Firefox an chromium look alright, also the titles of the windows are ok.

betaboon commented 3 years ago

i ran into the issue of gtkUsePortal = true; breaking gtk3-antialiasing a while ago myself.

d4g commented 3 years ago

i ran into the issue of gtkUsePortal = true; breaking gtk3-antialiasing a while ago myself.

Did you raise an according issue already?

betaboon commented 3 years ago

i dont remember, but dont think so

d4g commented 3 years ago

Ok, after a long debugging session, things are getting weird but somehow work ...

What I had to do:

  1. Add the following lines to my sway/config
    exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK DBUS_SESSION_BUS_ADDRESS
    exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK DBUS_SESSION_BUS_ADDRESS
  2. Manually enable the pipewire user service (I don't know why)
    systemctl --user enable pipewire
  3. Reboot
  4. Kill the xdg-desktop-portal service
    systemctl --user stop xdg-desktop-portal
  5. Manually start all 3 xdg-desktop-portal service
    /nix/store/9bj2y7s0i6pncrh8ijkllyiyrz8yfbqq-xdg-desktop-portal-1.8.0/libexec> ./xdg-desktop-portal -v -r
    /nix/store/sx9xfqxic42q2d61k3hk8f7d6ylrgx8v-xdg-desktop-portal-gtk-1.8.0/libexec> ./xdg-desktop-portal-gtk --replace --verbose
    /nix/store/fxhs00lfclai4p40xgslm8gm2b10w3dy-xdg-desktop-portal-wlr-0.1.0/libexec> ./xdg-desktop-portal-wlr -l DEBUG -o DP-2

    And now screen sharing ... works? And: After I did all this, the font rendering for NEW windows seems to be fixed. I don't understand why. Something is really really wrong and this is not the nix way of doing stuff.

d4g commented 3 years ago

I wrote the following "nix package" and start it via sway. If I reload the sway config (via super+shift+c), it also fixes font rendering in waybar.

xdg.nix


{ config, pkgs, ... }:

let 
  xdg-fix = pkgs.writeScriptBin "xdg-fix.sh" ''
    #!${pkgs.bash}/bin/sh
    ${pkgs.systemd}/bin/systemctl --user stop xdg-desktop-portal
    ${pkgs.procps}/bin/pkill xdg-desktop-portal
    ${pkgs.procps}/bin/pkill xdg-desktop-portal-gtk
    ${pkgs.procps}/bin/pkill xdg-desktop-portal-wlr
    ${pkgs.xdg-desktop-portal}/libexec/xdg-desktop-portal -v -r &
    ${pkgs.xdg-desktop-portal-gtk}/libexec/xdg-desktop-portal-gtk --replace --verbose &
    ${pkgs.xdg-desktop-portal-wlr}/libexec/xdg-desktop-portal-wlr -l DEBUG -o DP-2 &

  ''; 

in
{
  environment.systemPackages =  [
    xdg-fix
  ];  

}

and in .config/sway/config:

exec_always /run/current-system/sw/bin/xdg-fix.sh
Kazimazi commented 3 years ago

And now screen sharing ... works?

I did your steps, and got it working for the first time... I'd been trying for months. Got an error tho for ./xdg-desktop-portal-wlr -l DEBUG tho: [ERROR] - dbus: failed to acquire service name: File exists

gytis-ivaskevicius commented 3 years ago

Screen sharing seems to work file after commenting out GTK stuff:

  xdg.portal = {
    enable = true;
    #gtkUsePortal = true;
    extraPortals = with pkgs; [
      xdg-desktop-portal-wlr
      #xdg-desktop-portal-gtk
    ];
  };
d4g commented 3 years ago

@gytis-ivaskevicius I will try. How do you start chromium?

@Kazimazi its broken for me again. I don't know why.

primeos commented 3 years ago

In case anyone's interested to test this: #114979 (but be aware that chromium takes very long to build and that you need to cherry-pick (at least) 9f38162b3033a57f114e7601df95f257e94eb002 if you test on nixos-unstable). Switching to PipeWire 0.3 might help with this issue but it shouldn't magically fix those GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface ... errors.

primeos commented 3 years ago

I briefly tested #114979 and it worked for me after the following hack (hope the other stuff that I've tried before isn't relevant...):

$ xdg-desktop-portal --replace --verbose
$ # In my case:
$ # /nix/store/bmhnz3q8j61gbxpvm67vb41f2n6639j8-xdg-desktop-portal-1.8.1/libexec/xdg-desktop-portal -v -r

Anyway, that's a dirty hack and no proper solution but maybe it helps someone in the meantime.

The real problem should be in nixos/modules/config/xdg/portal.nix or pkgs/development/libraries/xdg-desktop-portal/default.nix as apparently at least the following DBus interface doesn't get installed/registered correctly:

/nix/store/bmhnz3q8j61gbxpvm67vb41f2n6639j8-xdg-desktop-portal-1.8.1/share/dbus-1/interfaces/org.freedesktop.impl.portal.ScreenCast.xml

Errors (journalctl, nixos-version: 0aeba64fb26e4defa0842a942757144659c6e29f):

Mar 04 17:23:58 quorra .xdg-desktop-po[4401]: A backend call failed: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.impl.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop
Mar 04 17:23:58 quorra .xdg-desktop-po[4401]: Failed to close session implementation: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.impl.portal.Session” on object at path /org/freedesktop/portal/desktop/session/1_2/webrtc_session448426574

(cc @worldofpeace (module) @jtojnar (package): FYI, in case you have time and motivation.)

tstelzer commented 3 years ago

I leave comment here to get news.

You don't have to. You can subscribe to issues (currently top-right in the UI), without adding an (arguably) pointless comment.

ulysses4ever commented 3 years ago

Just to add a datapoint here: I use Firefox and screen sharing on sway (nixos-unstable) does not work ootb, but suggested by @primeos "hack" (/path/to/xdg-desktop-portal -v -r) works -- thanks a lot, @primeos! (I spent hell a lot of time before found this). I also seem to have to restart the portal-wlr and portal services first: after logining in sway I have portal-wlr dead for some reason (after a manual restart it's ok), and because of that portal has some issues (again, after restarting both, seem to work ok).

Needless to say, I would be very grateful if someone could fix this.

ahdyt commented 3 years ago

Just to add a datapoint here: I use Firefox and screen sharing on sway (nixos-unstable) does not work ootb, but suggested by @primeos "hack" (/path/to/xdg-desktop-portal -v -r) works -- thanks a lot, @primeos! (I spent hell a lot of time before found this). I also seem to have to restart the portal-wlr and portal services first: after logining in sway I have portal-wlr dead for some reason (after a manual restart it's ok), and because of that portal has some issues (again, after restarting both, seem to work ok).

Needless to say, I would be very grateful if someone could fix this.

different case in mine, I just need to enable portal in config(tho I didn't check what's that options doing)

 xdg.portal.enable = true;
 xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ];

    environment.sessionVariables = {
      MOZ_ENABLE_WAYLAND = "1";
      XDG_CURRENT_DESKTOP = "sway"; # https://github.com/emersion/xdg-desktop-portal-wlr/issues/20
      XDG_SESSION_TYPE = "wayland"; # https://github.com/emersion/xdg-desktop-portal-wlr/pull/11
    };

and then replace the running portal with wlr version

/nix/store/v09agnrh58lgxyrpja0ajn30804jhmib-xdg-desktop-portal-wlr-e103e120e20e83acec5b66ce4cd33a0eb86df0b0/libexec/xdg-desktop-portal-wlr -r
ahdyt commented 3 years ago

Just to add a datapoint here: I use Firefox and screen sharing on sway (nixos-unstable) does not work ootb, but suggested by @primeos "hack" (/path/to/xdg-desktop-portal -v -r) works -- thanks a lot, @primeos! (I spent hell a lot of time before found this). I also seem to have to restart the portal-wlr and portal services first: after logining in sway I have portal-wlr dead for some reason (after a manual restart it's ok), and because of that portal has some issues (again, after restarting both, seem to work ok). Needless to say, I would be very grateful if someone could fix this.

different case in mine, I just need to enable portal in config(tho I didn't check what's that options doing)

 xdg.portal.enable = true;
 xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ];

    environment.sessionVariables = {
      MOZ_ENABLE_WAYLAND = "1";
      XDG_CURRENT_DESKTOP = "sway"; # https://github.com/emersion/xdg-desktop-portal-wlr/issues/20
      XDG_SESSION_TYPE = "wayland"; # https://github.com/emersion/xdg-desktop-portal-wlr/pull/11
    };

and then replace the running portal with wlr version

/nix/store/v09agnrh58lgxyrpja0ajn30804jhmib-xdg-desktop-portal-wlr-e103e120e20e83acec5b66ce4cd33a0eb86df0b0/libexec/xdg-desktop-portal-wlr -r

this will make it works on every apps/packages, firefox, chromium, obs, etc.

ulysses4ever commented 3 years ago

@ahdyt thanks! It's close to what I described, and I just checked: indeed, no need to restart services manually. The issue though is that it's clearly very user-unfriendly because I need to know the store path, which will be changing after every update.

ahdyt commented 3 years ago

@ahdyt thanks! It's close to what I described, and I just checked: indeed, no need to restart services manually. The issue though is that it's clearly very user-unfriendly because I need to know the store path, which will be changing after every update.

Just create a script package like what d4g done previously in above comment

ulysses4ever commented 3 years ago

@ahdyt that's a great point, thank you! I missed that comment completely. One thing though: if I create a file like that (e.g. xdg.nix), how do I make sure I have the module available under /run/current-system/sw/bin? Is it something like nix-env ??? xdg.nix? I tried several things but they all failed (Sorry, I'm a NixOS newbie)

Abdillah commented 3 years ago

@ulysses4ever Just import the file in your configuration.nix,

configuration.nix

{ config, pkgs, ... }:

{
    imports = [ ./xdg.nix ];

    # ...
}

Then rebuild..

ulysses4ever commented 3 years ago

It appears to me that systemctl --user restart xdg-desktop-portal-wlr is enough. Still feels like a bug.

gytis-ivaskevicius commented 3 years ago

Hey fellow Nixers, Can yall do me a favor and take a look at this comment I wrote <3 https://github.com/flathub/com.discordapp.Discord/issues/89#issuecomment-836191568 (And yes, it is related to screen sharing)

chaoflow commented 3 years ago

Latest unstable nixos channel with:

  xdg.portal.enable = true;
  xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ];
  xdg.portal.gtkUsePortal = true;

.zlogin:

if [ "$(tty)" = "/dev/tty1" ]; then
    export MOZ_ENABLE_WAYLAND=1
    export WLR_DRM_NO_MODIFIERS=1
    export XDG_CURRENT_DESKTOP=sway
    export XDG_SESSION_TYPE=wayland
    exec sway 2> /tmp/sway.debug.log
fi
systemctl --user restart xdg-desktop-portal-wlr.service
Job for xdg-desktop-portal-wlr.service failed because the control process exited with error code.
See "systemctl --user status xdg-desktop-portal-wlr.service" and "journalctl --user -xe" for details.
journalctl --user -xe
Mai 10 14:32:12 ida systemd[1215]: Starting Portal service (wlroots implementation)...
░░ Subject: Unit UNIT has begun start-up
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ Unit UNIT has begun starting up.
Mai 10 14:32:12 ida xdg-desktop-portal-wlr[12204]: 2021/05/10 14:32:12 [ERROR] - wayland: failed to connect to display
Mai 10 14:32:12 ida systemd[1215]: xdg-desktop-portal-wlr.service: Main process exited, code=exited, status=1/FAILURE
Mai 10 14:32:12 ida systemd[1215]: xdg-desktop-portal-wlr.service: Failed with result 'exit-code'.
Mai 10 14:32:12 ida systemd[1215]: Failed to start Portal service (wlroots implementation).
░░ Subject: Unit UNIT has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ Unit UNIT has failed.
░░
░░ The result is RESULT.
primeos commented 3 years ago

@chaoflow that's unfortunately Sway specific (xdg-desktop-portal-wlr ... [ERROR] - wayland: failed to connect to display), see https://github.com/NixOS/nixpkgs/issues/119445#issuecomment-820507505.

tl;dr: Adding both exec dbus-update-activation-environment WAYLAND_DISPLAY and exec systemctl --user import-environment WAYLAND_DISPLAY to your Sway configuration should fix it but we don't (yet) have a proper solution for Nixpkgs.

chaoflow commented 3 years ago

@chaoflow that's unfortunately Sway specific (xdg-desktop-portal-wlr ... [ERROR] - wayland: failed to connect to display), see #119445 (comment).

tl;dr: Adding both exec dbus-update-activation-environment WAYLAND_DISPLAY and exec systemctl --user import-environment WAYLAND_DISPLAY to your Sway configuration should fix it but we don't (yet) have a proper solution for Nixpkgs.

@primeos Thanks. With that xdg-desktop-portal-wlr is started again. However, screen sharing is still broken. That's #121678

clushie commented 3 years ago

Note: documentation on import-environment and dbus-update-activation-environment got ?recently? added to the swaywiki: https://github.com/swaywm/sway/wiki#gtk-applications-take-20-seconds-to-start, if your pavucontrol or any other application is very slow at starting up this is happening because of that commands missing.

I'm really happy that screensharing is finally working reliable.

primeos commented 3 years ago

For Sway users: While working on a PR I've noticed https://github.com/emersion/xdg-desktop-portal-wlr/commit/884a2e808e390a75137d68efe14521e2db38bc8e. I guess this might be the reason why it required hacks like running xdg-desktop-portal -v -r. I've added that to my PR #123034 and with that I didn't need to execute/restart anything manually. Feel free to test/reproduce (either need to copy the XDG_CURRENT_DESKTOP to your Sway configuration or add include /etc/sway/config.d/* which we've only added recently in #122605) and feedback is welcome.

ahdyt commented 3 years ago

For Sway users: While working on a PR I've noticed emersion/xdg-desktop-portal-wlr@884a2e8. I guess this might be the reason why it required hacks like running xdg-desktop-portal -v -r. I've added that to my PR #123034 and with that I didn't need to execute/restart anything manually. Feel free to test/reproduce (either need to copy the XDG_CURRENT_DESKTOP to your Sway configuration or add include /etc/sway/config.d/* which we've only added recently in #122605) and feedback is welcome.

Can't wait to have this in the nixos documentation, so that people can follow just easily, not everyone following from the beginning, and yes, without the hack to restart the portal ofc.

jansol commented 3 years ago

Something seems to be wrong in the plasma5 session too. Screen sharing / recording fails with: org.freedesktop.impl.portal.desktop.kde[25197]: xdp-kde-screencast: zkde_screencast_unstable_v1 does not seem to be available

Also it looks like there is no xdg-desktop-portal-kde user service at all, only the base xdg-desktop-portal service even though the plasma module explicitly adds the kde portal to extraPortals.

pasqui23 commented 2 years ago

https://github.com/NixOS/nixpkgs/pull/148344 fixes screensharing with firefox and obs, but not with chromium. Even with the fix there is no xdg-desktop-portal-kde user service and I don't think there should be.

nh2 commented 2 years ago

Could anybody summarise what the status in NixOS 21.11 is?

Is screen sharing (individual-window, and whole-screen respectively) supposed/reported to work in Firefox and Chromium?

pasqui23 commented 2 years ago

From my tests on plasma wayland on unstable: