How do I connect a snap to dbus?

I’m currently working on a snap for gnome-mpv, the code is here. It currently only works with devmode because I can’t figure out how to connect it to dbus properly. I have declared a plug with interface type dbus, but I can’t figure out into which slot the plug should go, because the core snap doesn’t seem to have a dbus slot.

Whenever the snap is launched with strict confinement I get:

Failed to register: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Connection ":1.1184" is not allowed to own the service "io.github.GnomeMpv" due to AppArmor policy

This is described here:

Basically, you need to do something along the lines of:

name: gnome-mpv
  dbus-daemon: # name this whatever you want
    interface: dbus
    bus: session
    name: org.gnome.mpv # adjust accordingly
    command: ...
    slots: [ dbus-daemon ]

Ie, you create a slot for your snap with the bus and well-known name that allows your snap to bind to the well-known name. It also provides the ability for other snaps to then plugs to your slot implementation. Importantly, the name you use for your slot (ie, ‘dbus-daemon’ in the above), is seen in snap interfaces and used in snap connect/disconnect). Choosing a name that makes sense in the context of these commands is recommended (eg, gnome-mpv:dbus is nicer than gnome-mpv:foo).

Do note that a snap declaration is needed for your snap to be delivered via the snap store and claim this dbus name. Simply upload your snap to the store and request a manual review and a reviewer can take a look.

1 Like

It works now, thanks!