cashmere

cashmere

How to fix screensharing for Niri WM under NixOS

Note

Everything written here is based on MY RESEARCH AND MY ASSUMPTIONS

Problem

The log output shows that xdg-desktop-portal assigns all interfaces to the GTK portal ("Choosing gtk.portal for…"), which means the system doesn't recognize a GNOME session. Without correct session detection, xdg-desktop-portal-gnome refuses to start because it requires an active graphical session.

Symptoms

Solution

If you have any xdg portal configs in your home manager then remove it

Add the following snippet to your configuration.nix:

xdg.portal = {
  enable = true;
  extraPortals = with pkgs; [
    xdg-desktop-portal-gtk
    xdg-desktop-portal-gnome
  ];
  config = {
    common = {
      default = [ "gtk" ];
    };
    niri = {
      default = [
        "gtk"
        "gnome"
      ];
      "org.freedesktop.impl.portal.ScreenCast" = [ "gnome" ];
      "org.freedesktop.impl.portal.Screenshot" = [ "gnome" ];
    };
  };
};

Add session environment variables to help portal detection:

environment.sessionVariables = {
  XDG_CURRENT_DESKTOP = "niri";
  XDG_SESSION_TYPE = "wayland";
  XDG_SESSION_DESKTOP = "niri";
};

Optionally add required GNOME packages:

environment.systemPackages = with pkgs; [
  gnome-keyring
  nautilus
];

Rebuild your system and restart your session:

sudo nixos-rebuild switch

Verification

After applying the fix, verify that screensharing works:

systemctl --user status xdg-desktop-portal-gnome.service

busctl --user call org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.ScreenCast CreateSession a{sv} 0

echo $XDG_CURRENT_DESKTOP
echo $XDG_SESSION_TYPE

Why this happens

Additional Notes