How to fix screensharing for Niri WM under NixOS

Table of Contents

Note

Everything written here is based on MY RESEARCH AND MY ASSUMPTIONS

1. 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.

1.1. Symptoms

  • busctl --user call org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.ScreenCast CreateSession a{sv} 0 returns “No such interface”
  • systemctl --user status xdg-desktop-portal-gnome.service shows “inactive (dead)”
  • Only GTK and WLR portals are running, but no GNOME portal

2. Solution

  1. If you have any xdg portal configs in your home manager then remove it
  2. Add the following snippet to your configuration.nix:

    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" ];
          };
        };
      };
    
  3. Add session environment variables to help portal detection:

    NIX
       environment.sessionVariables = {
         XDG_CURRENT_DESKTOP = "niri";
         XDG_SESSION_TYPE = "wayland";
         XDG_SESSION_DESKTOP = "niri";
       };
    
  4. Optionally add required GNOME packages:

    NIX
       environment.systemPackages = with pkgs; [
         gnome-keyring  # Implements the Secret Portal
         nautilus       # Required for File Chooser from xdg-desktop-portal-gnome 47.0+
       ];
    
  5. Rebuild your system and restart your session:

    BASH
       sudo nixos-rebuild switch
       # Then logout and login again, or reboot
    

3. Verification

After applying the fix, verify that screensharing works:

BASH
# Check if GNOME portal is running
systemctl --user status xdg-desktop-portal-gnome.service

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

# Check environment variables
echo $XDG_CURRENT_DESKTOP
echo $XDG_SESSION_TYPE

4. Why this happens

  • Niri requires xdg-desktop-portal-gnome specifically for screencasting functionality
  • Without proper session environment variables, the GNOME portal won’t start
  • The system falls back to GTK portal which doesn’t support ScreenCast interface
  • This became more prominent after xdg-desktop-portal version 1.17 changed how portal implementations are loaded

5. Additional Notes

  • Make sure to run Niri as a session (via niri-session or display manager), not in windowed mode
  • PipeWire must be running and properly configured for screencasting to work
  • The configuration creates explicit portal assignments for the Niri desktop environment