2010-07-13 09:22:52 +00:00
|
|
|
# D-Bus configuration and system bus daemon.
|
|
|
|
|
2022-11-17 15:02:34 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2007-06-08 18:56:55 +00:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
let
|
2009-08-10 18:25:09 +00:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
cfg = config.services.dbus;
|
|
|
|
|
2016-09-20 07:21:08 +00:00
|
|
|
homeDir = "/run/dbus";
|
2007-06-08 18:56:55 +00:00
|
|
|
|
2017-02-16 11:56:45 +00:00
|
|
|
configDir = pkgs.makeDBusConf {
|
2020-11-02 21:42:55 +00:00
|
|
|
inherit (cfg) apparmor;
|
2017-02-16 11:56:45 +00:00
|
|
|
suidHelper = "${config.security.wrapperDir}/dbus-daemon-launch-helper";
|
|
|
|
serviceDirectories = cfg.packages;
|
|
|
|
};
|
2007-06-08 18:56:55 +00:00
|
|
|
|
2023-03-07 03:21:48 +00:00
|
|
|
inherit (lib) mkOption mkEnableOption mkIf mkMerge types;
|
2022-11-17 15:16:18 +00:00
|
|
|
|
2009-08-10 18:25:09 +00:00
|
|
|
in
|
2007-06-08 18:56:55 +00:00
|
|
|
|
2009-08-10 18:25:09 +00:00
|
|
|
{
|
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2023-03-07 03:21:48 +00:00
|
|
|
boot.initrd.systemd.dbus = {
|
2023-07-03 12:41:38 +00:00
|
|
|
enable = mkEnableOption "dbus in stage 1";
|
2023-03-07 03:21:48 +00:00
|
|
|
};
|
|
|
|
|
2009-08-10 18:25:09 +00:00
|
|
|
services.dbus = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2013-10-28 15:14:15 +00:00
|
|
|
type = types.bool;
|
2016-03-07 01:38:53 +00:00
|
|
|
default = false;
|
2015-08-24 12:36:21 +00:00
|
|
|
internal = true;
|
2009-08-10 18:25:09 +00:00
|
|
|
description = ''
|
|
|
|
Whether to start the D-Bus message bus daemon, which is
|
|
|
|
required by many other system services and applications.
|
|
|
|
'';
|
|
|
|
};
|
2007-06-08 18:56:55 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
implementation = mkOption {
|
|
|
|
type = types.enum [ "dbus" "broker" ];
|
2024-04-29 11:00:27 +00:00
|
|
|
default = "dbus";
|
2021-02-12 09:36:23 +00:00
|
|
|
description = ''
|
|
|
|
The implementation to use for the message bus defined by the D-Bus specification.
|
|
|
|
Can be either the classic dbus daemon or dbus-broker, which aims to provide high
|
|
|
|
performance and reliability, while keeping compatibility to the D-Bus
|
|
|
|
reference implementation.
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-08-10 18:25:09 +00:00
|
|
|
packages = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.listOf types.path;
|
2016-03-07 01:38:53 +00:00
|
|
|
default = [ ];
|
2009-08-10 18:25:09 +00:00
|
|
|
description = ''
|
|
|
|
Packages whose D-Bus configuration files should be included in
|
2016-06-21 19:51:47 +00:00
|
|
|
the configuration of the D-Bus system-wide or session-wide
|
|
|
|
message bus. Specifically, files in the following directories
|
|
|
|
will be included into their respective DBus configuration paths:
|
2022-08-02 23:57:59 +00:00
|
|
|
{file}`«pkg»/etc/dbus-1/system.d`
|
|
|
|
{file}`«pkg»/share/dbus-1/system.d`
|
|
|
|
{file}`«pkg»/share/dbus-1/system-services`
|
|
|
|
{file}`«pkg»/etc/dbus-1/session.d`
|
|
|
|
{file}`«pkg»/share/dbus-1/session.d`
|
|
|
|
{file}`«pkg»/share/dbus-1/services`
|
2009-08-10 18:25:09 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-10-22 18:24:41 +00:00
|
|
|
|
2020-11-02 21:42:55 +00:00
|
|
|
apparmor = mkOption {
|
|
|
|
type = types.enum [ "enabled" "disabled" "required" ];
|
|
|
|
description = ''
|
|
|
|
AppArmor mode for dbus.
|
|
|
|
|
|
|
|
`enabled` enables mediation when it's
|
|
|
|
supported in the kernel, `disabled`
|
|
|
|
always disables AppArmor even with kernel support, and
|
|
|
|
`required` fails when AppArmor was not found
|
|
|
|
in the kernel.
|
|
|
|
'';
|
|
|
|
default = "disabled";
|
|
|
|
};
|
2009-08-10 18:25:09 +00:00
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
environment.etc."dbus-1".source = configDir;
|
2009-08-10 18:25:09 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
environment.pathsToLink = [
|
|
|
|
"/etc/dbus-1"
|
|
|
|
"/share/dbus-1"
|
|
|
|
];
|
2017-01-30 22:59:20 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
users.users.messagebus = {
|
|
|
|
uid = config.ids.uids.messagebus;
|
|
|
|
description = "D-Bus system message bus daemon user";
|
|
|
|
home = homeDir;
|
2023-10-17 10:09:12 +00:00
|
|
|
homeMode = "0755";
|
2021-02-12 09:36:23 +00:00
|
|
|
group = "messagebus";
|
|
|
|
};
|
2009-08-16 21:46:26 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
users.groups.messagebus.gid = config.ids.gids.messagebus;
|
2009-08-10 18:25:09 +00:00
|
|
|
|
2024-04-03 04:11:48 +00:00
|
|
|
# Install dbus for dbus tools even when using dbus-broker
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.dbus
|
|
|
|
];
|
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
# You still need the dbus reference implementation installed to use dbus-broker
|
|
|
|
systemd.packages = [
|
|
|
|
pkgs.dbus
|
|
|
|
];
|
2012-06-14 22:44:56 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
services.dbus.packages = [
|
|
|
|
pkgs.dbus
|
|
|
|
config.system.path
|
|
|
|
];
|
2009-08-16 21:46:26 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
systemd.user.sockets.dbus.wantedBy = [
|
|
|
|
"sockets.target"
|
|
|
|
];
|
|
|
|
}
|
2010-07-26 14:10:04 +00:00
|
|
|
|
2023-03-07 03:21:48 +00:00
|
|
|
(mkIf config.boot.initrd.systemd.dbus.enable {
|
|
|
|
boot.initrd.systemd = {
|
|
|
|
users.messagebus = { };
|
|
|
|
groups.messagebus = { };
|
|
|
|
contents."/etc/dbus-1".source = pkgs.makeDBusConf {
|
|
|
|
inherit (cfg) apparmor;
|
|
|
|
suidHelper = "/bin/false";
|
2024-05-22 00:52:42 +00:00
|
|
|
serviceDirectories = [ pkgs.dbus config.boot.initrd.systemd.package ];
|
2023-03-07 03:21:48 +00:00
|
|
|
};
|
|
|
|
packages = [ pkgs.dbus ];
|
2024-05-22 00:52:42 +00:00
|
|
|
storePaths = [
|
|
|
|
"${pkgs.dbus}/bin/dbus-daemon"
|
|
|
|
"${config.boot.initrd.systemd.package}/share/dbus-1/system-services"
|
|
|
|
"${config.boot.initrd.systemd.package}/share/dbus-1/system.d"
|
|
|
|
];
|
2023-03-07 03:21:48 +00:00
|
|
|
targets.sockets.wants = [ "dbus.socket" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
(mkIf (cfg.implementation == "dbus") {
|
|
|
|
security.wrappers.dbus-daemon-launch-helper = {
|
|
|
|
source = "${pkgs.dbus}/libexec/dbus-daemon-launch-helper";
|
|
|
|
owner = "root";
|
|
|
|
group = "messagebus";
|
|
|
|
setuid = true;
|
|
|
|
setgid = false;
|
|
|
|
permissions = "u+rx,g+rx,o-rx";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.dbus = {
|
2024-05-04 16:12:54 +00:00
|
|
|
aliases = [
|
|
|
|
# hack aiding to prevent dbus from restarting when switching from dbus-broker back to dbus
|
|
|
|
"dbus-broker.service"
|
|
|
|
];
|
2021-02-12 09:36:23 +00:00
|
|
|
# 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;
|
|
|
|
};
|
2022-11-17 15:16:18 +00:00
|
|
|
};
|
2015-04-01 14:28:18 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
systemd.user.services.dbus = {
|
2024-05-04 16:12:54 +00:00
|
|
|
aliases = [
|
|
|
|
# hack aiding to prevent dbus from restarting when switching from dbus-broker back to dbus
|
|
|
|
"dbus-broker.service"
|
|
|
|
];
|
2021-02-12 09:36:23 +00:00
|
|
|
# Don't restart dbus-daemon. Bad things tend to happen if we do.
|
|
|
|
reloadIfChanged = true;
|
|
|
|
restartTriggers = [
|
|
|
|
configDir
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.implementation == "broker") {
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.dbus-broker
|
2022-11-17 15:16:18 +00:00
|
|
|
];
|
2015-04-16 17:10:11 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
systemd.packages = [
|
|
|
|
pkgs.dbus-broker
|
|
|
|
];
|
2022-11-17 15:16:18 +00:00
|
|
|
|
2021-02-12 09:36:23 +00:00
|
|
|
# Just to be sure we don't restart through the unit alias
|
|
|
|
systemd.services.dbus.reloadIfChanged = true;
|
|
|
|
systemd.user.services.dbus.reloadIfChanged = true;
|
|
|
|
|
|
|
|
# NixOS Systemd Module doesn't respect 'Install'
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/108643
|
|
|
|
systemd.services.dbus-broker = {
|
|
|
|
aliases = [
|
2024-05-04 16:12:54 +00:00
|
|
|
# allow other services to just depend on dbus,
|
|
|
|
# but also a hack aiding to prevent dbus from restarting when switching from dbus-broker back to dbus
|
2021-02-12 09:36:23 +00:00
|
|
|
"dbus.service"
|
|
|
|
];
|
2023-12-13 18:34:23 +00:00
|
|
|
unitConfig = {
|
|
|
|
# We get errors when reloading the dbus-broker service
|
|
|
|
# if /tmp got remounted after this service started
|
|
|
|
RequiresMountsFor = [ "/tmp" ];
|
|
|
|
};
|
2021-02-12 09:36:23 +00:00
|
|
|
# Don't restart dbus. Bad things tend to happen if we do.
|
|
|
|
reloadIfChanged = true;
|
|
|
|
restartTriggers = [
|
|
|
|
configDir
|
|
|
|
];
|
|
|
|
environment = {
|
|
|
|
LD_LIBRARY_PATH = config.system.nssModules.path;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.user.services.dbus-broker = {
|
|
|
|
aliases = [
|
2024-05-04 16:12:54 +00:00
|
|
|
# allow other services to just depend on dbus,
|
|
|
|
# but also a hack aiding to prevent dbus from restarting when switching from dbus-broker back to dbus
|
2021-02-12 09:36:23 +00:00
|
|
|
"dbus.service"
|
|
|
|
];
|
|
|
|
# Don't restart dbus. Bad things tend to happen if we do.
|
|
|
|
reloadIfChanged = true;
|
|
|
|
restartTriggers = [
|
|
|
|
configDir
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
]);
|
2007-06-08 18:56:55 +00:00
|
|
|
}
|