Qt app cannot connect to session bus

I trying to get a VPN client running on NixOS. The binaries have all their dependencies resolved and the application runs, but it reports that it cannot connect to the D-Bus session bus:

2020-04-10,15:21:02:223, 10685,10685,, 1, /LinuxService.h, 75, bool f5::qt::setupDBusService(f5::qt::CustomQApplication&), Cannot connect to session bus

Here’s my expression:

{ stdenv
, dpkg
, makeWrapper
, buildFHSUserEnv
, glib
, libGL
, libxml2
, libxslt
, fontconfig
, freetype
, sqlite
, libICE
, libSM
, libXcomposite
, libXi
, libXrender
, xkeyboard_config
}:

let
  f5vpn-dpkg = stdenv.mkDerivation {
    name = "f5vpn-dpkg";
    src = ./linux_f5vpn.x86_64.deb;

    nativeBuildInputs = [
      dpkg
      makeWrapper
      xkeyboard_config
    ];

    dontConfigure = true;
    dontBuild = true;

    sourceRoot = ".";
    unpackCmd = ''dpkg -x $src $out'';

    installPhase = ''
      makeWrapper \
          $out/opt/f5/vpn/f5vpn \
          $out/bin/f5vpn \
          --prefix "QT_XKB_CONFIG_ROOT" ":" "${xkeyboard_config}/share/X11/xkb"
      mkdir -p $out/share/applications
      cp $out/opt/f5/vpn/com.f5.f5vpn.desktop $out/share/applications
      substituteInPlace \
          $out/share/applications/com.f5.f5vpn.desktop \
          --replace "/opt/f5/vpn/f5vpn" "$out/bin/f5vpn"
      mkdir -p $out/share/dbus-1/services
      cp $out/opt/f5/vpn/com.f5.f5vpn.service $out/share/dbus-1/services
      substituteInPlace \
          $out/share/dbus-1/services/com.f5.f5vpn.service \
          --replace "/opt/f5/vpn/f5vpn" "$out/bin/f5vpn"
    '';

    preFixup = ''
      patchelf --remove-rpath $out/opt/f5/vpn/f5vpn
      patchelf --set-rpath $out/opt/f5/vpn/lib $out/opt/f5/vpn/f5vpn
    '';
  };
in
  buildFHSUserEnv {
    name = "f5vpn-fhs";
    targetPkgs = pkgs: [
      f5vpn-dpkg
      pkgs.glib
      pkgs.libGL
      pkgs.libxml2
      pkgs.libxslt
      pkgs.fontconfig
      pkgs.freetype
      pkgs.sqlite
      pkgs.xorg.libICE
      pkgs.xorg.libSM
      pkgs.xorg.libX11
      pkgs.xorg.libxcb
      pkgs.xorg.libXcomposite
      pkgs.xorg.libXext
      pkgs.xorg.libXi
      pkgs.xorg.libXrender
      pkgs.zlib
    ];
    runScript = "f5vpn";
  }

I went for buildFHSUserEnv because I can see that it relies on some absolute paths when I run it on Ubuntu, but the same thing happens if I build it with autoPatchelfHook.

It’s worth mentioning that with steam-run, the application actually gets past the session bus point, but there are other issues (eventually a segfault), and I really don’t want to go down that road without understanding why it won’t work in my own FHS sandbox.

I also tried using the Qt-specific mkDerivation (as outlined in Nixpkgs 23.11 manual | Nix & NixOS), but I cannot see how that would matter since I already resolved the dependencies. It didn’t make a difference anyway.

Any ideas? Are there any differences in how NixOS handles D-Bus compared to other distros?

How are you running it?

The application is meant to be invoked by Firefox via D-Bus, but since it cannot make that connection I use dbus-monitor to see what arguments the browser tries to call it with, and run that on the command line. That works on my reference OS.

So I build, install and run f5vpn-fhs [args].

I’m guessing that the fhs env doesn’t inherit your DBUS_SESSION_BUS_ADDRESS variable. What happens if you do echo $DBUS_SESSION_BUS_ADDRESS inside the environment?

DBUS_SESSION_BUS_ADDRESS is unix:abstract=/tmp/dbus-kUlK1qRnsn,guid=7ceee477209ad70e4a23d6e05eb0101d - the same address as outside of the FHS. Which looks valid, right? Tried unsetting it see if the program would complain about it, but the same log statement stands.

Mine looks like this:

unix:path=/run/user/1000/bus

I’m guessing that you have something spawning dbus instead of having it socket activated and /tmp is then a separate filesystem inside the env.

Set services.dbus.socketActivated = true; (this really should be the default), nixos-rebuild, log out and back in, check $DBUS_SESSION_BUS_ADDRESS and if it looks like mine, it should work.

That makes sense - I’ll keep that setting regardless - but alas, it did not make a difference. I checked the address and it looks just like yours inside the FHS environment.

Hard to tell how it tries to connect since I don’t have access to the source, but I assume it’s using the Qt D-Bus API. As I said above, I do have a reference working install on Ubuntu - perhaps there is somewhere I can look for hints on how it (successfully) connects there?

(btw thanks for answering these!)

Try to execute this inside the env:

dbus-send \
   --session \
   --type=method_call \
   --print-reply \
   --dest=org.freedesktop.DBus \
   /org/freedesktop/DBus org.freedesktop.DBus.ListNames

This will tell you if you can connect to dbus. Then try again with --session replaced by --system and see if you can connect to the system dbus.

Looks like I can connect to both buses from inside the environment:

$ dbus-send --session --type=method_call --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames
method return time=1588753394.340692 sender=org.freedesktop.DBus -> destination=:1.25 serial=3 reply_serial=2
   array [
      string "org.freedesktop.DBus"
      string "org.freedesktop.PowerManagement"
      (...)
      string ":1.5"
      string ":1.6"
   ]
$ dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames
method return time=1588753405.450942 sender=org.freedesktop.DBus -> destination=:1.72 serial=3 reply_serial=2
   array [
      string "org.freedesktop.DBus"
      string "org.freedesktop.login1"
      (...)
      string "fi.w1.wpa_supplicant1"
      string "org.freedesktop.Accounts"
   ]

I’m out of ideas. Maybe open a ticket with the vendor?

In case anyone else needs to install the F5 VPN client with Nix and finds this: I never managed to get it working, but I found this and packaged it for Nix: GitHub - evenbrenden/svpn-login: Connect to a F5 BIG-IP APM VPN server using the FastPPP protocol without any graphical frontend