Skip to content

calbrecht/nixpkgs-overlays

Repository files navigation

Firefox screensharing on sway and NixOs master

Since nixpkgs@master 2020-09-21 this overlay is obsolete for firefox screen casting capabilities under sway wayland

When NixOS/nixpkgs#84233 got merged into nixpkgs master, firefox-wayland pkg provides full support for casting the screen under sway wayland sessions.

The required configuration.nix attrs are:

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

  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
  };
  
  services.pipewire.enable = true;
}

Also it turned out, you will need to put the following line into your ~/.config/sway/config

exec systemctl --user import-environment
# and maybe also
exec systemctl --user start graphical-session.target

Also it seems to depend on how sway is started and if xdg-desktop-portal is running as a user service.

And it does not like to run beside gdm

For me, it works because i do start sway after login on tty1, like so

{
  environment.interactiveShellInit = ''
    if test `tty` = /dev/tty1; then
       exec sway
    fi
  '';
}

To verify your setup is working, try mozilla gum_test.

For testing screen casting capability without the browser xdp-screen-cast.py.sh nix-shell python script converted from xdp-screen-cast.py found through emersion/xdg-desktop-portal-wlr/wiki/Screencast-Compatibility might be helpful as well.


Obsolete as of nixpkgs@master 2020-09-21

You need the overlays for firefox-wayland-pipewire-unwrapped, firefox-wayland-pipewire and pipewire, also xdg-desktop-portal-wlr from nixpkgs-wayland

Please note: Everytime i reboot my system, i have to restart all the services using the sway shortcut mentioned below, else they are not started in correct order and fail.

in your /etc/configuration.nix

{
  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
  };
    
  services.pipewire.enable = false;
 
  xdg = {
    icons.enable = true;
    portal = {
      enable = true;
      extraPortals = [
        pkgs.xdg-desktop-portal-gtk
        pkgs.xdg-desktop-portal-wlr
      ];
      gtkUsePortal = true;
    };
  };

  systemd = {
    user.services.pipewire = {
      enable = true;
      description = "Multimedia Service";

      environment = {
        PIPEWIRE_DEBUG = "4";
      };
      path = [ pkgs.pipewire ];
      requires= [ "pipewire.socket" "xdg-desktop-portal.service" ];

      serviceConfig = {
        Type = "simple";
        ExecStart = "${pkgs.pipewire}/bin/pipewire";
        Restart = "on-failure";
      };

      wantedBy = [ "default.target" ];
    };

    user.sockets.pipewire = {
      enable = true;

      socketConfig = {
        Priority = 6;
        Backlog = 5;
        ListenStream= "%t/pipewire-0";
      };
    };

    user.services.xdg-desktop-portal-wlr = {
      enable = true;
      description = "Portal service (wlroots implementation)";

      requires= [ "pipewire.service" ];

      serviceConfig = {
        Type = "dbus";
        BusName = "org.freedesktop.impl.portal.desktop.wlr";
        ExecStart = [ 
          "" # Override for trace
          "${pkgs.xdg-desktop-portal-wlr}/libexec/xdg-desktop-portal-wlr -l TRACE" 
        ];
        Restart = "on-failure";
      };
    };
  };
  users.extraUsers.user.extraGroups = [ "video" ];
}

in sway for restarting the services (if anything broke)

bindsym $mod+Shift+s exec "systemctl --user stop xdg-desktop-portal.service \
&& systemctl --user stop xdg-desktop-portal-wlr.service \
&& systemctl --user stop pipewire.service \
&& systemctl --user start pipewire.service \
&& sleep 1\
&& systemctl --user start xdg-desktop-portal-wlr.service \
&& systemctl --user start xdg-desktop-portal.service \
&& notify-send -t 1000 screensharing restarted"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published