2008-11-23 02:28:58 +01:00
|
|
|
# D-Bus system-wide daemon.
|
2008-12-04 16:48:27 +01:00
|
|
|
{pkgs, config, ...}:
|
2007-06-08 20:56:55 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
with pkgs.lib;
|
2008-11-23 02:28:58 +01:00
|
|
|
|
|
|
|
let
|
2009-08-10 20:25:09 +02:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
cfg = config.services.dbus;
|
|
|
|
|
2009-08-16 23:46:26 +02:00
|
|
|
# !!! dbus_temp uses /etc/dbus-1; will be merged into pkgs.dbus later.
|
|
|
|
dbus = pkgs.dbus_temp;
|
2007-06-08 20:56:55 +02:00
|
|
|
|
|
|
|
homeDir = "/var/run/dbus";
|
|
|
|
|
2009-08-16 23:46:26 +02:00
|
|
|
configDir = pkgs.stdenv.mkDerivation {
|
2007-06-08 20:56:55 +02:00
|
|
|
name = "dbus-conf";
|
2009-08-10 20:25:09 +02:00
|
|
|
buildCommand = ''
|
2007-06-08 20:56:55 +02:00
|
|
|
ensureDir $out
|
2009-08-16 23:46:26 +02:00
|
|
|
|
2009-08-17 03:16:38 +02:00
|
|
|
ln -s ${dbus}/etc/dbus-1/session.conf $out/session.conf
|
|
|
|
|
2009-08-16 23:46:26 +02:00
|
|
|
cp ${dbus}/etc/dbus-1/system.conf $out/system.conf
|
|
|
|
|
|
|
|
# Tell the daemon where the setuid wrapper around
|
|
|
|
# dbus-daemon-launch-helper lives.
|
|
|
|
sed -i $out/system.conf \
|
|
|
|
-e 's|<servicehelper>.*/libexec/dbus-daemon-launch-helper|<servicehelper>${config.security.wrapperDir}/dbus-daemon-launch-helper|'
|
|
|
|
|
|
|
|
# Add the system-services directories to the daemon's search path.
|
|
|
|
sed -i $out/system.conf \
|
|
|
|
-e 's|<standard_system_servicedirs/>|${systemServiceDirs}|'
|
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
# Note: system.conf includes ./system.d (i.e. it has a relative,
|
|
|
|
# not absolute path).
|
2009-08-17 03:16:38 +02:00
|
|
|
ensureDir $out/session.d
|
2007-06-09 22:05:04 +02:00
|
|
|
ensureDir $out/system.d
|
2009-08-17 03:16:38 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
for i in ${toString cfg.packages}; do
|
2009-08-17 03:16:38 +02:00
|
|
|
for j in $i/etc/dbus-1/session.d/*; do
|
|
|
|
ln -s $j $out/session.d/
|
|
|
|
done
|
|
|
|
for j in $i/etc/dbus-1/system.d/*; do
|
|
|
|
ln -s $j $out/system.d/
|
|
|
|
done
|
2007-06-09 22:05:04 +02:00
|
|
|
done
|
2009-08-10 20:25:09 +02:00
|
|
|
''; # */
|
2007-06-08 20:56:55 +02:00
|
|
|
};
|
|
|
|
|
2009-08-16 23:46:26 +02:00
|
|
|
systemServiceDirs = concatMapStrings
|
|
|
|
(d: "<servicedir>${d}/share/dbus-1/system-services</servicedir> ")
|
|
|
|
cfg.packages;
|
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
in
|
2007-06-08 20:56:55 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
{
|
2007-06-08 20:56:55 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
###### interface
|
2007-06-08 20:56:55 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.dbus = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to start the D-Bus message bus daemon, which is
|
|
|
|
required by many other system services and applications.
|
|
|
|
'';
|
|
|
|
merge = pkgs.lib.mergeEnableOption;
|
|
|
|
};
|
2007-06-08 20:56:55 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
packages = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Packages whose D-Bus configuration files should be included in
|
|
|
|
the configuration of the D-Bus system-wide message bus.
|
|
|
|
Specifically, every file in
|
|
|
|
<filename><replaceable>pkg</replaceable>/etc/dbus-1/system.d</filename>
|
|
|
|
is included.
|
|
|
|
'';
|
|
|
|
};
|
2007-06-08 20:56:55 +02:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
};
|
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
###### implementation
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
config = mkIf cfg.enable {
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
environment.systemPackages = [dbus.daemon dbus.tools];
|
|
|
|
|
2009-08-16 23:46:26 +02:00
|
|
|
environment.etc = singleton
|
|
|
|
# We need /etc/dbus-1/system.conf for now, because
|
|
|
|
# dbus-daemon-launch-helper is called with an empty environment
|
|
|
|
# and no arguments. So we have no way to tell it the location
|
|
|
|
# of our config file.
|
|
|
|
{ source = configDir;
|
|
|
|
target = "dbus-1";
|
|
|
|
};
|
|
|
|
|
2009-08-10 20:25:09 +02:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "messagebus";
|
|
|
|
uid = config.ids.uids.messagebus;
|
|
|
|
description = "D-Bus system message bus daemon user";
|
|
|
|
home = homeDir;
|
2009-08-16 23:46:26 +02:00
|
|
|
group = "messagebus";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "messagebus";
|
|
|
|
gid = config.ids.gids.messagebus;
|
2009-08-10 20:25:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
jobs = singleton
|
|
|
|
{ name = "dbus";
|
|
|
|
|
|
|
|
startOn = "startup";
|
|
|
|
stopOn = "shutdown";
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${homeDir}
|
|
|
|
chown messagebus ${homeDir}
|
|
|
|
|
|
|
|
mkdir -m 0755 -p /var/lib/dbus
|
|
|
|
${dbus.tools}/bin/dbus-uuidgen --ensure
|
|
|
|
|
|
|
|
rm -f ${homeDir}/pid
|
|
|
|
# !!! hack - dbus should be running once this job is
|
|
|
|
# considered "running"; should be fixable once we have
|
|
|
|
# Upstart 0.6.
|
2009-08-16 23:46:26 +02:00
|
|
|
${dbus}/bin/dbus-daemon --config-file=${configDir}/system.conf
|
2009-08-10 20:25:09 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
pid=$(cat ${homeDir}/pid)
|
|
|
|
if test -n "$pid"; then
|
|
|
|
kill -9 $pid
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2009-08-16 23:46:26 +02:00
|
|
|
security.setuidOwners = singleton
|
|
|
|
{ program = "dbus-daemon-launch-helper";
|
|
|
|
source = "${dbus}/libexec/dbus-daemon-launch-helper";
|
|
|
|
owner = "root";
|
|
|
|
group = "messagebus";
|
|
|
|
setuid = true;
|
|
|
|
setgid = false;
|
|
|
|
permissions = "u+rx,g+rx,o-rx";
|
|
|
|
};
|
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
2009-08-10 20:25:09 +02:00
|
|
|
|
2007-06-08 20:56:55 +02:00
|
|
|
}
|