Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/dbus: support dbus-broker #112879

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/avahi-daemon.nix
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ in
};
};

services.dbus.enable = true;
services.dbus.enable = mkDefault true;
services.dbus.packages = [ pkgs.avahi ];

networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 5353 ];
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/wicd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ with lib;
script = "${pkgs.wicd}/sbin/wicd -f";
};

services.dbus.enable = true;
services.dbus.enable = mkDefault true;
services.dbus.packages = [pkgs.wicd];
};
}
161 changes: 112 additions & 49 deletions nixos/modules/services/system/dbus.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let

cfg = config.services.dbus;

brokerCfg = config.services.dbus-broker;

homeDir = "/run/dbus";

configDir = pkgs.makeDBusConf {
Expand All @@ -23,6 +25,17 @@ in

options = {

services.dbus-broker.enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable dbus-broker, implementation of a message bus
as defined by the D-Bus specification. Its aim is to provide high
performance and reliability, while keeping compatibility to the D-Bus
reference implementation. You must disable services.dbus.enable to use this.
'';
};

services.dbus = {

enable = mkOption {
Expand Down Expand Up @@ -79,61 +92,111 @@ in

###### implementation

config = mkIf cfg.enable {
warnings = optional (cfg.socketActivated != null) (
let
files = showFiles options.services.dbus.socketActivated.files;
in
"The option 'services.dbus.socketActivated' in ${files} no longer has"
+ " any effect and can be safely removed: the user D-Bus session is"
+ " now always socket activated."
);

environment.systemPackages = [ pkgs.dbus.daemon pkgs.dbus ];

environment.etc."dbus-1".source = configDir;

users.users.messagebus = {
uid = config.ids.uids.messagebus;
description = "D-Bus system message bus daemon user";
home = homeDir;
group = "messagebus";
};

users.groups.messagebus.gid = config.ids.gids.messagebus;
config = mkMerge [
# You still need the dbus reference implementation installed to use dbus-broker
(mkIf (cfg.enable || brokerCfg.enable) {
warnings = optional (cfg.socketActivated != null) (
let
files = showFiles options.services.dbus.socketActivated.files;
in
"The option 'services.dbus.socketActivated' in ${files} no longer has"
+ " any effect and can be safely removed: the user D-Bus session is"
+ " now always socket activated."
);

assertions = [
{ assertion = brokerCfg.enable -> !cfg.enable;
message = ''
You cannot use services.dbus.enable with services.dbus-broker.enable. Please disable DBus.
'';
}
];

environment.etc."dbus-1".source = configDir;

users.users.messagebus = {
uid = config.ids.uids.messagebus;
description = "D-Bus system message bus daemon user";
home = homeDir;
group = "messagebus";
};

systemd.packages = [ pkgs.dbus.daemon ];
users.groups.messagebus.gid = config.ids.gids.messagebus;

security.wrappers.dbus-daemon-launch-helper = {
source = "${pkgs.dbus.daemon}/libexec/dbus-daemon-launch-helper";
owner = "root";
group = "messagebus";
setuid = true;
setgid = false;
permissions = "u+rx,g+rx,o-rx";
};
systemd.packages = [
pkgs.dbus.daemon
];

services.dbus.packages = [
pkgs.dbus.out
config.system.path
];
services.dbus.packages = [
pkgs.dbus.out
config.system.path
];

systemd.services.dbus = {
# Don't restart dbus-daemon. Bad things tend to happen if we do.
reloadIfChanged = true;
restartTriggers = [ configDir ];
environment = { LD_LIBRARY_PATH = config.system.nssModules.path; };
};

systemd.user = {
services.dbus = {
systemd.services.dbus = {
# Don't restart dbus-daemon. Bad things tend to happen if we do.
reloadIfChanged = true;
restartTriggers = [ configDir ];
restartTriggers = [
configDir
];
environment = {
LD_LIBRARY_PATH = config.system.nssModules.path;
};
};
sockets.dbus.wantedBy = [ "sockets.target" ];
};

environment.pathsToLink = [ "/etc/dbus-1" "/share/dbus-1" ];
};
systemd.user = {
services.dbus = {
# Don't restart dbus-daemon. Bad things tend to happen if we do.
reloadIfChanged = true;
restartTriggers = [
configDir
];
};
sockets.dbus.wantedBy = [
"sockets.target"
];
};

environment.pathsToLink = [
"/etc/dbus-1"
"/share/dbus-1"
];
})

(mkIf cfg.enable {
environment.systemPackages = [
pkgs.dbus
pkgs.dbus.daemon
];

security.wrappers.dbus-daemon-launch-helper = {
source = "${pkgs.dbus.daemon}/libexec/dbus-daemon-launch-helper";
owner = "root";
group = "messagebus";
setuid = true;
setgid = false;
permissions = "u+rx,g+rx,o-rx";
};
})

(mkIf brokerCfg.enable {
environment.systemPackages = [
pkgs.dbus-broker
];

systemd.packages = [
pkgs.dbus-broker
];

# NixOS Systemd Module doesn't respect 'Install'
# https://github.com/NixOS/nixpkgs/issues/108643
systemd.services.dbus-broker.aliases = [
"dbus.service"
];

systemd.user.services.dbus-broker.aliases = [
"dbus.service"
];
})

];
}
2 changes: 1 addition & 1 deletion nixos/modules/services/x11/display-managers/lightdm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ in
environment.etc."lightdm/lightdm.conf".source = lightdmConf;
environment.etc."lightdm/users.conf".source = usersConf;

services.dbus.enable = true;
services.dbus.enable = mkDefault true;
services.dbus.packages = [ lightdm ];

# lightdm uses the accounts daemon to remember language/window-manager per user
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/boot/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ in
"systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; };
});

services.dbus.enable = true;
services.dbus.enable = mkDefault true;

users.users.systemd-network.uid = config.ids.uids.systemd-network;
users.groups.systemd-network.gid = config.ids.gids.systemd-network;
Expand Down
55 changes: 42 additions & 13 deletions pkgs/os-specific/linux/dbus-broker/default.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
{ lib, stdenv, fetchFromGitHub, docutils, meson, ninja, pkg-config
, dbus, linuxHeaders, systemd }:
{ lib
, stdenv
, fetchFromGitHub
, docutils
, meson
, ninja
, pkg-config
, dbus
, linuxHeaders
, systemd
}:

stdenv.mkDerivation rec {
pname = "dbus-broker";
version = "22";
version = "26";

src = fetchFromGitHub {
owner = "bus1";
repo = "dbus-broker";
rev = "v${version}";
sha256 = "0vxr73afix5wjxy8g4cckwhl242rrlazm52673iwmdyfz5nskj2x";
owner = "bus1";
repo = "dbus-broker";
rev = "v${version}";
sha256 = "QjYjAvnLgMRL/4Jj1XBXl9z47zVHclOqZrAF2khC424=";
fetchSubmodules = true;
};

nativeBuildInputs = [ docutils meson ninja pkg-config ];
patches = [
# Make launcher.c use nixos dbus configuration paths
# In the future the buildsystem should allow us to configure the **default**
# (as there is a --config-file cmdline)
./fix-paths.patch
];

buildInputs = [ dbus linuxHeaders systemd ];
mesonFlags = [
"-D=system-console-users=gdm,sddm,lightdm"
];

nativeBuildInputs = [
docutils
meson
ninja
pkg-config
];

buildInputs = [
dbus
linuxHeaders
systemd
];

PKG_CONFIG_SYSTEMD_SYSTEMDSYSTEMUNITDIR = "${placeholder "out"}/lib/systemd/system";
PKG_CONFIG_SYSTEMD_SYSTEMDUSERUNITDIR = "${placeholder "out"}/lib/systemd/user";
Expand All @@ -32,9 +61,9 @@ stdenv.mkDerivation rec {

meta = with lib; {
description = "Linux D-Bus Message Broker";
homepage = "https://github.com/bus1/dbus-broker/wiki";
license = licenses.asl20;
platforms = platforms.linux;
maintainers = with maintainers; [ peterhoeg ];
homepage = "https://github.com/bus1/dbus-broker/wiki";
license = licenses.asl20;
platforms = platforms.linux;
maintainers = with maintainers; [ peterhoeg worldofpeace ];
};
}
16 changes: 16 additions & 0 deletions pkgs/os-specific/linux/dbus-broker/fix-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/src/launch/launcher.c b/src/launch/launcher.c
index 5ba9b77..e338d92 100644
--- a/src/launch/launcher.c
+++ b/src/launch/launcher.c
@@ -1007,9 +1007,9 @@ static int launcher_parse_config(Launcher *launcher, ConfigRoot **rootp, NSSCach
if (launcher->configfile)
configfile = launcher->configfile;
else if (launcher->user_scope)
- configfile = "/usr/share/dbus-1/session.conf";
+ configfile = "/etc/dbus-1/session.conf";
else
- configfile = "/usr/share/dbus-1/system.conf";
+ configfile = "/etc/dbus-1/system.conf";

config_parser_init(&parser);