2010-07-13 10:22:52 +01:00
|
|
|
# D-Bus configuration and system bus daemon.
|
|
|
|
|
|
|
|
{ config, pkgs, ... }:
|
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;
|
|
|
|
|
2007-06-08 19:56:55 +01:00
|
|
|
homeDir = "/var/run/dbus";
|
|
|
|
|
2009-08-16 22:46:26 +01:00
|
|
|
configDir = 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
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-08-26 14:46:59 +01:00
|
|
|
cp -v ${pkgs.dbus_daemon}/etc/dbus-1/system.conf $out/system.conf
|
2009-08-16 22:46:26 +01:00
|
|
|
|
2010-07-13 10:22:52 +01:00
|
|
|
# !!! Hm, these `sed' calls are rather error-prone...
|
|
|
|
|
2009-08-16 22:46:26 +01:00
|
|
|
# Tell the daemon where the setuid wrapper around
|
2011-09-14 19:20:50 +01:00
|
|
|
# dbus-daemon-launch-helper lives.
|
2009-08-16 22:46:26 +01:00
|
|
|
sed -i $out/system.conf \
|
|
|
|
-e 's|<servicehelper>.*/libexec/dbus-daemon-launch-helper|<servicehelper>${config.security.wrapperDir}/dbus-daemon-launch-helper|'
|
|
|
|
|
2010-07-13 10:22:52 +01:00
|
|
|
# Add the system-services and system.d directories to the system
|
|
|
|
# bus search path.
|
2009-08-16 22:46:26 +01:00
|
|
|
sed -i $out/system.conf \
|
2010-07-26 15:10:04 +01:00
|
|
|
-e 's|<standard_system_servicedirs/>|${systemServiceDirs}|' \
|
|
|
|
-e 's|<includedir>system.d</includedir>|${systemIncludeDirs}|'
|
2010-07-13 10:22:52 +01:00
|
|
|
|
2011-08-26 14:46:59 +01:00
|
|
|
cp ${pkgs.dbus_daemon}/etc/dbus-1/session.conf $out/session.conf
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-07-13 10:22:52 +01:00
|
|
|
# Add the services and session.d directories to the session bus
|
|
|
|
# search path.
|
|
|
|
sed -i $out/session.conf \
|
2011-09-08 00:07:05 +01:00
|
|
|
-e 's|<standard_session_servicedirs />|${sessionServiceDirs}&|' \
|
2010-07-26 15:10:04 +01:00
|
|
|
-e 's|<includedir>session.d</includedir>|${sessionIncludeDirs}|'
|
2009-08-10 19:25:09 +01:00
|
|
|
''; # */
|
2007-06-08 19:56:55 +01:00
|
|
|
};
|
|
|
|
|
2009-08-16 22:46:26 +01:00
|
|
|
systemServiceDirs = concatMapStrings
|
|
|
|
(d: "<servicedir>${d}/share/dbus-1/system-services</servicedir> ")
|
|
|
|
cfg.packages;
|
|
|
|
|
2010-07-26 15:10:04 +01:00
|
|
|
systemIncludeDirs = concatMapStrings
|
|
|
|
(d: "<includedir>${d}/etc/dbus-1/system.d</includedir> ")
|
|
|
|
cfg.packages;
|
|
|
|
|
2010-07-13 10:22:52 +01:00
|
|
|
sessionServiceDirs = concatMapStrings
|
|
|
|
(d: "<servicedir>${d}/share/dbus-1/services</servicedir> ")
|
|
|
|
cfg.packages;
|
|
|
|
|
2010-07-26 15:10:04 +01:00
|
|
|
sessionIncludeDirs = concatMapStrings
|
|
|
|
(d: "<includedir>${d}/etc/dbus-1/session.d</includedir> ")
|
|
|
|
cfg.packages;
|
|
|
|
|
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 = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
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
|
|
|
};
|
2011-09-14 19:20:50 +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
|
|
|
|
2011-08-26 14:46:59 +01:00
|
|
|
environment.systemPackages = [ pkgs.dbus_daemon pkgs.dbus_tools ];
|
2009-08-10 19:25:09 +01:00
|
|
|
|
2009-08-16 22:46:26 +01:00
|
|
|
environment.etc = singleton
|
|
|
|
{ source = configDir;
|
|
|
|
target = "dbus-1";
|
|
|
|
};
|
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "messagebus";
|
|
|
|
uid = config.ids.uids.messagebus;
|
|
|
|
description = "D-Bus system message bus daemon user";
|
|
|
|
home = homeDir;
|
2009-08-16 22:46:26 +01:00
|
|
|
group = "messagebus";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "messagebus";
|
|
|
|
gid = config.ids.gids.messagebus;
|
2009-08-10 19:25:09 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.dbus =
|
2009-12-16 19:45:11 +00:00
|
|
|
{ startOn = "started udev and started syslogd";
|
2009-08-10 19:25:09 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${homeDir}
|
|
|
|
chown messagebus ${homeDir}
|
|
|
|
|
|
|
|
mkdir -m 0755 -p /var/lib/dbus
|
2011-08-26 14:46:59 +01:00
|
|
|
${pkgs.dbus_tools}/bin/dbus-uuidgen --ensure
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
rm -f ${homeDir}/pid
|
|
|
|
'';
|
|
|
|
|
2009-11-06 15:23:16 +00:00
|
|
|
daemonType = "fork";
|
|
|
|
|
2011-08-26 14:46:59 +01:00
|
|
|
exec = "${pkgs.dbus_daemon}/bin/dbus-daemon --system";
|
2009-11-06 15:23:16 +00:00
|
|
|
|
2009-08-10 19:25:09 +01:00
|
|
|
postStop =
|
|
|
|
''
|
2009-09-26 00:18:52 +01:00
|
|
|
# !!! Hack: doesn't belong here.
|
2009-11-06 15:23:16 +00:00
|
|
|
pid=$(cat /var/run/ConsoleKit/pid || true)
|
2009-09-26 00:18:52 +01:00
|
|
|
if test -n "$pid"; then
|
2009-11-06 15:23:16 +00:00
|
|
|
kill $pid || true
|
|
|
|
rm -f /var/run/ConsoleKit/pid
|
2009-08-10 19:25:09 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-08-16 22:46:26 +01:00
|
|
|
security.setuidOwners = singleton
|
|
|
|
{ program = "dbus-daemon-launch-helper";
|
2011-08-26 14:46:59 +01:00
|
|
|
source = "${pkgs.dbus_daemon}/libexec/dbus-daemon-launch-helper";
|
2009-08-16 22:46:26 +01:00
|
|
|
owner = "root";
|
|
|
|
group = "messagebus";
|
|
|
|
setuid = true;
|
|
|
|
setgid = false;
|
|
|
|
permissions = "u+rx,g+rx,o-rx";
|
|
|
|
};
|
|
|
|
|
2010-07-26 15:10:04 +01:00
|
|
|
services.dbus.packages =
|
2011-10-29 22:03:57 +01:00
|
|
|
[ "${config.nixpkgs.config.nix.stateDir}/nix/profiles/default"
|
2010-07-26 15:10:04 +01:00
|
|
|
config.system.path
|
|
|
|
];
|
|
|
|
|
2010-08-09 12:42:32 +01:00
|
|
|
environment.pathsToLink = [ "/etc/dbus-1" "/share/dbus-1" ];
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2007-06-08 19:56:55 +01:00
|
|
|
}
|