Reproducible problem with sway, waybar, dbus and pulseaudio

Consider this minimal configuration.nix file:

{ config, pkgs, ... }:

{
  imports = [
    /etc/nixos/hardware-configuration.nix
  ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  boot.initrd.luks.devices."luks-cb0ef3ca-374c-40a8-98cb-cd48d2e6ff2f".device =
    "/dev/disk/by-uuid/cb0ef3ca-374c-40a8-98cb-cd48d2e6ff2f";

  networking.networkmanager.enable = true;

  users.users.bisect = {
    isNormalUser = true;
  };

  environment.systemPackages = with pkgs; [
    waybar
  ];
  
  programs.sway = {
    enable = true;
  };

  system.stateVersion = "23.11";
}

If I activate it using nixos-rebuild switch, reboot, login as user “bisect”, run sway, press Ctrl+Enter to get a graphical terminal, and run waybar there, waybar starts just fine.

If however, I add these two lines, as recommended here

services.pipewire.enable = false;
services.pulseaudio.enable = true;

Running waybar works fine, as long as I do it approx. 30 seconds after sway starts. If I run waybar earlier, it won’t show up and this is printed to stdout/stderr:

[bisect@nixos:~]$ waybar 
[2025-05-30 11:53:57.576] [info] Using configuration file /nix/store/l2aw7jhndlv442d6gnnz910mlvvk0x6b-waybar-0.12.0/etc/xdg/waybar/config.jsonc
[2025-05-30 11:54:22.612] [error] Error calling StartServiceByName for org.freedesktop.portal.Desktop: Timeout was reached

After some debugging, I noticed that the timeframe where running waybar won’t work, matches exactly with the timeframe where

busctl --user call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus NameHasOwner s org.freedesktop.portal.Desktop

prints b false. I don’t know what to do with that information though.

Use pipewire, not pulseaudio. I don’t know why anyone’d want to use PA with sway.