Help building a python package that uses dbus

Hi, I am relatively new to packaging and lately I have tried to get a python package to work on NixOS.
The package at hand is osdlyrics and the following code gets the package installed.

{ stdenv
, lib
, pkg-config
, autoconf
, python3
, gtk2
, dbus-glib
, dbus
, libnotify
, automake
, fetchFromGitHub
, intltool
, libappindicator-gtk2
, desktop-file-utils
, mpd
, sqlite
, gobject-introspection
, libpthreadstubs
}:

stdenv.mkDerivation rec {
  pname = "osdlyrics";
  version = "0.5.5-rc2";

  src = fetchFromGitHub {
    owner = "osdlyrics";
    repo = pname;
    rev = version;
    sha256 = "1cgm38xyx4f9grlb0n72xcwgibgqhqy7v6fkdiispyndlxy7w0j9";
  };

  python = python3.withPackages (
    ps: [
      ps.future ps.pydbus ps.dbus-python ps.pygobject3
      ps.pygobject2 ps.pycurl ps.chardet
    ]
  );

  nativeBuildInputs = [
    autoconf
    automake
    pkg-config
  ];

  propagatedBuildInputs = [
    intltool
    python
    gtk2
    dbus-glib
    libnotify
    libappindicator-gtk2
    desktop-file-utils
    mpd
    sqlite
    gobject-introspection
    libpthreadstubs
  ];

  installPhase = ''
    runHook preInstall

    patchShebangs ./autogen.sh

    substituteInPlace autogen.sh \
      --replace "/usr/bin/python2" "${python}/bin/python"
      
    ./autogen.sh --prefix=$out PYTHON=${python}/bin/python
    make
    make install

    mkdir -p $out/lib/osdlyrics/daemon/osdlyrics/
    cp -r $out/${python.sitePackages}/osdlyrics/* $out/lib/osdlyrics/daemon/osdlyrics/

    runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://github.com/osdlyrics/osdlyrics";
    description = "Displays synced lyrics for songs";
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [ dasj19 ];
  };
}

There are 3 binaries in $out/bin and osdlyrics-daemon fails to find and execute dbus services that are crucial for the application to work.

osdlyrics-daemon 
WARNING:root:Cannot activate proxy org.osdlyrics.PlayerProxy.Http: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.PlayerProxy.Http exited with status 1
WARNING:root:Cannot activate proxy org.osdlyrics.PlayerProxy.Mpd: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.PlayerProxy.Mpd exited with status 1
WARNING:root:Cannot activate proxy org.osdlyrics.PlayerProxy.Mpris1: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.PlayerProxy.Mpris1 exited with status 1
WARNING:root:Cannot activate proxy org.osdlyrics.PlayerProxy.Mpris2: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.PlayerProxy.Mpris2 exited with status 1
WARNING:root:Cannot activate lyric source org.osdlyrics.LyricSourcePlugin.xiami: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.LyricSourcePlugin.xiami exited with status 1
WARNING:root:Cannot activate lyric source org.osdlyrics.LyricSourcePlugin.viewlyrics: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.LyricSourcePlugin.viewlyrics exited with status 1
WARNING:root:Cannot activate lyric source org.osdlyrics.LyricSourcePlugin.netease: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.LyricSourcePlugin.netease exited with status 1
WARNING:root:Cannot activate lyric source org.osdlyrics.LyricSourcePlugin.lrc123: org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.osdlyrics.LyricSourcePlugin.lrc123 exited with status 1

What am I missing in the package definition?

Have you tried to register the services using services.dbus.packages option?

Thanks for telling me about that option. did not know about it… however I am not sure I use it corectly. I have tried using it in my configuration.nix … and it does not take those errors away. I have also tried using it in the package definition but i believe that requires to split the package in two … osdlyrics and osdlyrics-daemon. Is that the way to go? or am I misunderstanding something…

Plus the documentation says that this path: pkg/share/dbus-1/services is read automatically by Dbus. So it should read those files by default…

It is a NixOS option so it goes to configuration.nix. But yeah, environment.systemPackages will be added to the option automatically thanks to the following two lines:

Looking closer at the errors, it ends with status 1 (it is not the case the services are not found) so I would check the systemd journal to see if any more details about the failure to start the services are logged. If not, I would try to start the services manually (the exec paths in the dbus-service files).

Thank you @jtojnar for the help provided, it really made my day. I located the issue and now I have a mostly working build.
I’ll try to make it better before submitting it to nixpkgs.