2008-11-23 01:28:58 +00:00
|
|
|
# D-Bus system-wide daemon.
|
2008-12-04 15:48:27 +00:00
|
|
|
{pkgs, config, ...}:
|
2007-06-08 19:56:55 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
with pkgs.lib;
|
2008-11-23 01:28:58 +00:00
|
|
|
|
|
|
|
let
|
2009-08-10 19:25:09 +01:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
cfg = config.services.dbus;
|
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
inherit (pkgs) dbus;
|
2007-06-08 19:56:55 +01:00
|
|
|
|
|
|
|
homeDir = "/var/run/dbus";
|
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
configFile = pkgs.stdenv.mkDerivation {
|
2007-06-08 19:56:55 +01:00
|
|
|
name = "dbus-conf";
|
2009-08-10 19:25:09 +01:00
|
|
|
buildCommand = ''
|
2007-06-08 19:56:55 +01:00
|
|
|
ensureDir $out
|
2009-04-03 23:04:31 +01:00
|
|
|
ln -s ${dbus}/etc/dbus-1/system.conf $out/system.conf
|
2007-06-09 21:05:04 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
# Note: system.conf includes ./system.d (i.e. it has a relative,
|
|
|
|
# not absolute path).
|
2007-06-09 21:05:04 +01:00
|
|
|
ensureDir $out/system.d
|
2009-08-10 19:25:09 +01:00
|
|
|
for i in ${toString cfg.packages}; do
|
2007-06-09 21:05:04 +01:00
|
|
|
ln -s $i/etc/dbus-1/system.d/* $out/system.d/
|
|
|
|
done
|
2009-08-10 19:25:09 +01:00
|
|
|
''; # */
|
2007-06-08 19:56:55 +01:00
|
|
|
};
|
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
in
|
2007-06-08 19:56:55 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
{
|
2007-06-08 19:56:55 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
###### interface
|
2007-06-08 19:56:55 +01:00
|
|
|
|
2009-08-10 19:25:09 +01: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 19:56:55 +01:00
|
|
|
|
2009-08-10 19:25:09 +01: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 19:56:55 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
};
|
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
###### implementation
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
config = mkIf cfg.enable {
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
environment.systemPackages = [dbus.daemon dbus.tools];
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "messagebus";
|
|
|
|
uid = config.ids.uids.messagebus;
|
|
|
|
description = "D-Bus system message bus daemon user";
|
|
|
|
home = homeDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
${dbus}/bin/dbus-daemon --config-file=${configFile}/system.conf
|
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
pid=$(cat ${homeDir}/pid)
|
|
|
|
if test -n "$pid"; then
|
|
|
|
kill -9 $pid
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
|
|
|
|
};
|
2009-08-10 19:25:09 +01:00
|
|
|
|
2007-06-08 19:56:55 +01:00
|
|
|
}
|