Change in dbus config file

How can I add a line to the system.conf dbus config?

Specifically, I would like to set this parameter:

<limit name="max_connections_per_user">512</limit>

The best way to start seems: pkgs/development/libraries/dbus/make-system-conf.xsl

But It is unclear to me how to insert this, without hard-coding it inside the xsl file.

Meta Information: NixOS 21.11. Not yet published server software requires a lot of open dbus connections.

You could open a pull request to Nixpkgs, doing something like the following:

--- a/pkgs/development/libraries/dbus/make-dbus-conf.nix
+++ b/pkgs/development/libraries/dbus/make-dbus-conf.nix
@@ -1,7 +1,13 @@
-{ runCommand, writeText, libxslt, dbus
+{ runCommand
+, lib
+, writeText
+, libxslt
+, dbus
 , serviceDirectories ? []
 , suidHelper ? "/var/setuid-wrappers/dbus-daemon-launch-helper"
 , apparmor ? "disabled" # one of enabled, disabled, required
+, extraSystemConfig
+, extraSessionConfig
 }:
 
 /* DBus has two configuration parsers -- normal and "trivial", which is used
@@ -34,11 +40,13 @@ runCommand "dbus-1"
     xsltproc --nonet \
       --stringparam serviceDirectories "$serviceDirectories" \
       --stringparam suidHelper "$suidHelper" \
+      --stringparam extraConfig ${lib.escapeShellArg extraSystemConfig} \
       --stringparam apparmor "$apparmor" \
       ${./make-system-conf.xsl} ${dbus}/share/dbus-1/system.conf \
       > $out/system.conf
     xsltproc --nonet \
       --stringparam serviceDirectories "$serviceDirectories" \
+      --stringparam extraConfig ${lib.escapeShellArg extraSessionConfig} \
       --stringparam apparmor "$apparmor" \
       ${./make-session-conf.xsl} ${dbus}/share/dbus-1/session.conf \
       > $out/session.conf
--- a/pkgs/development/libraries/dbus/make-system-conf.xsl
+++ b/pkgs/development/libraries/dbus/make-system-conf.xsl
@@ -17,6 +17,7 @@
   <xsl:param name="serviceDirectories" />
   <xsl:param name="suidHelper" />
   <xsl:param name="apparmor" />
+  <xsl:param name="extraConfig" />
 
   <xsl:template match="/busconfig">
     <busconfig>
@@ -28,6 +29,8 @@
       <!-- set suid helper -->
       <servicehelper><xsl:value-of select="$suidHelper" /></servicehelper>
 
+      <xsl:value-of select="$extraConfig" disable-output-escaping="yes" />
+
       <xsl:for-each select="str:tokenize($serviceDirectories)">
         <servicedir><xsl:value-of select="." />/share/dbus-1/system-services</servicedir>
         <includedir><xsl:value-of select="." />/etc/dbus-1/system.d</includedir>
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -16970,9 +16970,15 @@ with pkgs;
   dbus-sharp-glib-1_0 = callPackage ../development/libraries/dbus-sharp-glib/dbus-sharp-glib-1.0.nix { };
   dbus-sharp-glib-2_0 = callPackage ../development/libraries/dbus-sharp-glib { };
 
-  makeDBusConf = { suidHelper, serviceDirectories, apparmor ? "disabled" }:
+  makeDBusConf =
+    { suidHelper
+    , serviceDirectories
+    , apparmor ? "disabled"
+    , extraSystemConfig ? ""
+    , extraSessionConfig ? ""
+    }:
     callPackage ../development/libraries/dbus/make-dbus-conf.nix {
-      inherit suidHelper serviceDirectories apparmor;
+      inherit suidHelper serviceDirectories apparmor extraSystemConfig extraSessionConfig;
     };
 
   dee = callPackage ../development/libraries/dee {

But looking at dbus-daemon(1), passing something like the following to serviceDirectories argument might also work:

(writeTextFile rec {
  name = "custom-limits.conf";
  destination = "/share/dbus-1/system.d/${name}";
  text = ''
    <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
     "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
    <busconfig>
      <limit name="max_connections_per_user">512</limit>
    </busconfig>
  '';
})
2 Likes