2010-07-13 02:22:52 -07:00
|
|
|
# D-Bus configuration and system bus daemon.
|
|
|
|
|
2014-04-14 07:26:48 -07:00
|
|
|
{ config, lib, pkgs, ... }:
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2014-04-14 07:26:48 -07:00
|
|
|
with lib;
|
2008-11-22 17:28:58 -08:00
|
|
|
|
|
|
|
let
|
2009-08-10 11:25:09 -07:00
|
|
|
|
2008-11-22 17:28:58 -08:00
|
|
|
cfg = config.services.dbus;
|
|
|
|
|
2016-09-20 00:21:08 -07:00
|
|
|
homeDir = "/run/dbus";
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2016-03-06 17:38:53 -08:00
|
|
|
systemExtraxml = concatStrings (flip concatMap cfg.packages (d: [
|
|
|
|
"<servicedir>${d}/share/dbus-1/system-services</servicedir>"
|
|
|
|
"<includedir>${d}/etc/dbus-1/system.d</includedir>"
|
|
|
|
]));
|
|
|
|
|
|
|
|
sessionExtraxml = concatStrings (flip concatMap cfg.packages (d: [
|
|
|
|
"<servicedir>${d}/share/dbus-1/services</servicedir>"
|
|
|
|
"<includedir>${d}/etc/dbus-1/session.d</includedir>"
|
|
|
|
]));
|
|
|
|
|
2016-09-20 00:21:08 -07:00
|
|
|
daemonArgs = "--address=systemd: --nofork --nopidfile --systemd-activation";
|
|
|
|
|
2016-09-27 06:26:37 -07:00
|
|
|
configDir = pkgs.runCommand "dbus-conf"
|
|
|
|
{ preferLocalBuild = true;
|
|
|
|
allowSubstitutes = false;
|
|
|
|
}
|
|
|
|
''
|
2014-06-30 05:56:10 -07:00
|
|
|
mkdir -p $out
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2016-09-20 00:21:08 -07:00
|
|
|
cp ${pkgs.dbus.out}/share/dbus-1/{system,session}.conf $out
|
|
|
|
|
|
|
|
# avoid circular includes
|
|
|
|
sed -ri 's@(<include ignore_missing="yes">/etc/dbus-1/(system|session)\.conf</include>)@<!-- \1 -->@g' $out/{system,session}.conf
|
|
|
|
|
|
|
|
# include by full path
|
|
|
|
sed -ri "s@/etc/dbus-1/(system|session)-@$out/\1-@" $out/{system,session}.conf
|
|
|
|
|
2016-03-06 17:38:53 -08:00
|
|
|
sed '${./dbus-system-local.conf.in}' \
|
|
|
|
-e 's,@servicehelper@,${config.security.wrapperDir}/dbus-daemon-launch-helper,g' \
|
|
|
|
-e 's,@extra@,${systemExtraxml},' \
|
|
|
|
> "$out/system-local.conf"
|
2010-07-13 02:22:52 -07:00
|
|
|
|
2016-03-06 17:38:53 -08:00
|
|
|
sed '${./dbus-session-local.conf.in}' \
|
|
|
|
-e 's,@extra@,${sessionExtraxml},' \
|
|
|
|
> "$out/session-local.conf"
|
|
|
|
'';
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
in
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
{
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
###### interface
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
options = {
|
2011-09-14 11:20:50 -07:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
services.dbus = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2013-10-28 08:14:15 -07:00
|
|
|
type = types.bool;
|
2016-03-06 17:38:53 -08:00
|
|
|
default = false;
|
2015-08-24 05:36:21 -07:00
|
|
|
internal = true;
|
2009-08-10 11:25:09 -07:00
|
|
|
description = ''
|
|
|
|
Whether to start the D-Bus message bus daemon, which is
|
|
|
|
required by many other system services and applications.
|
|
|
|
'';
|
|
|
|
};
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
packages = mkOption {
|
2013-10-30 09:37:45 -07:00
|
|
|
type = types.listOf types.path;
|
2016-03-06 17:38:53 -08:00
|
|
|
default = [ ];
|
2009-08-10 11:25:09 -07:00
|
|
|
description = ''
|
|
|
|
Packages whose D-Bus configuration files should be included in
|
2016-06-21 12:51:47 -07: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:
|
2009-08-10 11:25:09 -07:00
|
|
|
<filename><replaceable>pkg</replaceable>/etc/dbus-1/system.d</filename>
|
2016-06-21 12:51:47 -07:00
|
|
|
<filename><replaceable>pkg</replaceable>/share/dbus-1/system-services</filename>
|
|
|
|
<filename><replaceable>pkg</replaceable>/etc/dbus-1/session.d</filename>
|
|
|
|
<filename><replaceable>pkg</replaceable>/share/dbus-1/services</filename>
|
2009-08-10 11:25:09 -07:00
|
|
|
'';
|
|
|
|
};
|
2007-06-08 11:56:55 -07:00
|
|
|
|
2016-09-20 00:21:08 -07:00
|
|
|
socketActivated = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Make the user instance socket activated.
|
|
|
|
'';
|
|
|
|
};
|
2009-08-10 11:25:09 -07:00
|
|
|
};
|
2008-11-22 17:28:58 -08:00
|
|
|
};
|
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
###### implementation
|
2008-11-22 17:28:58 -08:00
|
|
|
|
2009-08-10 11:25:09 -07:00
|
|
|
config = mkIf cfg.enable {
|
2008-11-22 17:28:58 -08:00
|
|
|
|
2016-09-05 04:38:16 -07:00
|
|
|
environment.systemPackages = [ pkgs.dbus.daemon pkgs.dbus ];
|
2009-08-10 11:25:09 -07:00
|
|
|
|
2009-08-16 14:46:26 -07:00
|
|
|
environment.etc = singleton
|
|
|
|
{ source = configDir;
|
|
|
|
target = "dbus-1";
|
|
|
|
};
|
|
|
|
|
2013-08-23 02:33:24 -07:00
|
|
|
users.extraUsers.messagebus = {
|
|
|
|
uid = config.ids.uids.messagebus;
|
|
|
|
description = "D-Bus system message bus daemon user";
|
|
|
|
home = homeDir;
|
|
|
|
group = "messagebus";
|
|
|
|
};
|
2009-08-16 14:46:26 -07:00
|
|
|
|
2013-08-23 02:33:24 -07:00
|
|
|
users.extraGroups.messagebus.gid = config.ids.gids.messagebus;
|
2009-08-10 11:25:09 -07:00
|
|
|
|
2014-04-22 06:36:39 -07:00
|
|
|
systemd.packages = [ pkgs.dbus.daemon ];
|
2012-06-14 15:44:56 -07:00
|
|
|
|
2009-08-16 14:46:26 -07:00
|
|
|
security.setuidOwners = singleton
|
|
|
|
{ program = "dbus-daemon-launch-helper";
|
2016-09-05 04:38:16 -07:00
|
|
|
source = "${pkgs.dbus.daemon}/libexec/dbus-daemon-launch-helper";
|
2009-08-16 14:46:26 -07:00
|
|
|
owner = "root";
|
|
|
|
group = "messagebus";
|
|
|
|
setuid = true;
|
|
|
|
setgid = false;
|
|
|
|
permissions = "u+rx,g+rx,o-rx";
|
|
|
|
};
|
|
|
|
|
2016-03-06 17:38:53 -08:00
|
|
|
services.dbus.packages = [
|
2016-05-18 12:57:35 -07:00
|
|
|
pkgs.dbus.out
|
2016-03-06 17:38:53 -08:00
|
|
|
config.system.path
|
|
|
|
];
|
2010-07-26 07:10:04 -07:00
|
|
|
|
2016-09-20 00:21:08 -07:00
|
|
|
systemd.services.dbus = {
|
|
|
|
# Don't restart dbus-daemon. Bad things tend to happen if we do.
|
|
|
|
reloadIfChanged = true;
|
|
|
|
restartTriggers = [ configDir ];
|
|
|
|
serviceConfig.ExecStart = [
|
|
|
|
""
|
|
|
|
"${lib.getBin pkgs.dbus}/bin/dbus-daemon --config-file=${configDir}/system.conf ${daemonArgs}"
|
|
|
|
];
|
|
|
|
};
|
2015-04-01 07:28:18 -07:00
|
|
|
|
2016-09-20 00:21:08 -07:00
|
|
|
systemd.user = {
|
|
|
|
services.dbus = {
|
|
|
|
# Don't restart dbus-daemon. Bad things tend to happen if we do.
|
|
|
|
reloadIfChanged = true;
|
|
|
|
restartTriggers = [ configDir ];
|
|
|
|
serviceConfig.ExecStart = [
|
|
|
|
""
|
|
|
|
"${lib.getBin pkgs.dbus}/bin/dbus-daemon --config-file=${configDir}/session.conf ${daemonArgs}"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
sockets.dbus.wantedBy = mkIf cfg.socketActivated [ "sockets.target" ];
|
|
|
|
};
|
2015-04-16 10:10:11 -07:00
|
|
|
|
2010-08-09 04:42:32 -07:00
|
|
|
environment.pathsToLink = [ "/etc/dbus-1" "/share/dbus-1" ];
|
2008-11-22 17:28:58 -08:00
|
|
|
};
|
2007-06-08 11:56:55 -07:00
|
|
|
}
|