How to fix screensharing for Niri WM under NixOS
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
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
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 # Implements the Secret Portal nautilus # Required for File Chooser from xdg-desktop-portal-gnome 47.0+ ];
-
Rebuild your system and restart your session:
# Then logout and login again, or reboot
Verification
After applying the fix, verify that screensharing works:
# Check if GNOME portal is running
# Test ScreenCast interface availability
# Check environment variables
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
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