Skip to content

Instantly share code, notes, and snippets.

@DuaneNielsen
Created February 17, 2026 18:03
Show Gist options
  • Select an option

  • Save DuaneNielsen/e30e364754ce1b089dcb21c38fd609f5 to your computer and use it in GitHub Desktop.

Select an option

Save DuaneNielsen/e30e364754ce1b089dcb21c38fd609f5 to your computer and use it in GitHub Desktop.
Fix waybar not starting with niri compositor - portal timeout issue
# Fixing Waybar Not Starting with Niri Compositor
## Problem
Waybar fails to start when launched by niri, with errors like:
```
Error calling StartServiceByName for org.freedesktop.portal.Desktop: Failed to activate service 'org.freedesktop.portal.Desktop': timed out
```
Or in portal logs:
```
xdg-desktop-portal-gtk: cannot open display:
```
## Root Cause
Niri sets `WAYLAND_DISPLAY`, `DISPLAY`, and other environment variables for its child processes, but **systemd user services don't inherit these**. The xdg-desktop-portal services are started by systemd, not spawned by niri, so they can't connect to the Wayland display.
Waybar depends on portals for some features (like appearance detection), so it times out waiting for the portal service that's failing silently in the background.
## Solution
Export the environment variables to systemd and dbus **before** spawning waybar.
Add this to your `~/.config/niri/config.kdl` before any other spawn-at-startup commands:
```kdl
// Export environment to systemd/dbus so portals and other services can connect
spawn-at-startup "sh" "-c" "systemctl --user import-environment WAYLAND_DISPLAY DISPLAY XDG_CURRENT_DESKTOP && dbus-update-activation-environment --systemd WAYLAND_DISPLAY DISPLAY XDG_CURRENT_DESKTOP"
// Now waybar can start properly
spawn-at-startup "waybar"
```
## Manual Fix (Current Session)
If you need to fix this without restarting niri:
```bash
# Export env vars to systemd
systemctl --user import-environment WAYLAND_DISPLAY DISPLAY XDG_CURRENT_DESKTOP
dbus-update-activation-environment --systemd WAYLAND_DISPLAY DISPLAY XDG_CURRENT_DESKTOP
# Restart portals
systemctl --user restart xdg-desktop-portal-gtk xdg-desktop-portal
# Now start waybar
waybar &
```
## Debugging Tips
Check if systemd has the display variables:
```bash
systemctl --user show-environment | grep -E "WAYLAND|DISPLAY"
```
Check portal status:
```bash
systemctl --user status xdg-desktop-portal-gtk
```
## Notes
- This affects any application that relies on portals when not started directly as a child of niri
- The `niri-session` wrapper handles this when niri is run via systemd, but not when run directly from a TTY
- Other Wayland compositors (sway, Hyprland) have similar issues and similar solutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment