Allow multiple calls to dbus combinator

Before this change, additional calls to the dbus combinator would add
multiple `xdg-dbus-proxy` instances, but only the latest call would be
forwarded into the jail.

With this change, all permissions are saved in state, then, in a
deferred `add-runtime` we add a single `xdg-dbus-proxy` exposing the
union of all previous dbus calls.

This should allow writing combinators that expose dbus permissions like
notifications, or reading light/dark mode changes which can be composed
just like the other non-dbus combinators.
This commit is contained in:
Alex David 2025-09-28 15:44:36 -07:00
commit 3610987241
3 changed files with 113 additions and 37 deletions

View file

@ -145,6 +145,41 @@ spec = inTestM $ do
sendDBusOutput `shouldBe` "Failed to call dbus method\n"
methodCalls `shouldBe` []
describe "multiple calls to the dbus combinator" $ do
it "exposes a union of all of the specified permissions" $ do
let mockMethod1 =
MockDBusMethod
{ objPath = "/foo/object1",
ifaceName = "foo.iface1.Iface",
methodName = "method1"
}
let mockMethod2 =
MockDBusMethod
{ objPath = "/foo/object2",
ifaceName = "foo.iface2.Iface",
methodName = "method2"
}
((sendDBusOutput, method2Calls), method1Calls) <- withDBusClient $ \mockBusName client -> do
withMockDBusMethodHandler client mockMethod1 "return value 1" $ do
withMockDBusMethodHandler client mockMethod2 "return value 2" $ do
runNixDrv
[i|
jail
"send-multiple"
(sh ''
${lib.getExe (#{callDBusMethodNixDrv mockBusName mockMethod1 "arg1"})}
${lib.getExe (#{callDBusMethodNixDrv mockBusName mockMethod2 "arg2"})}
'')
(c: [
(c.dbus { call = [ #{toNixString $ toProxyRule mockBusName mockMethod1} ]; })
(c.dbus { call = [ #{toNixString $ toProxyRule mockBusName mockMethod2} ]; })
])
|]
liftIO $ do
sendDBusOutput `shouldBe` " return value 1 return value 2"
method1Calls `shouldBe` ["arg1"]
method2Calls `shouldBe` ["arg2"]
-- * DBus test helpers
withDBusClient :: (DBus.BusName -> DBus.Client -> TestM a) -> TestM a