1{ stdenv, lib, fetchurl, pkgconfig, expat, systemd
2, libX11 ? null, libICE ? null, libSM ? null, x11Support ? (stdenv.isLinux || stdenv.isDarwin) }:
3
4assert x11Support -> libX11 != null
5 && libICE != null
6 && libSM != null;
7
8let
9 version = "1.10.24";
10 sha256 = "06ydmrg76l1kwl3190d72zpiy3qxy248x6gskxbj9qiqfsr4w63i";
11
12self = stdenv.mkDerivation {
13 name = "dbus-${version}";
14 inherit version;
15
16 src = fetchurl {
17 url = "http://dbus.freedesktop.org/releases/dbus/dbus-${version}.tar.gz";
18 inherit sha256;
19 };
20
21 patches = lib.optional stdenv.isSunOS ./implement-getgrouplist.patch;
22 postPatch = ''
23 substituteInPlace tools/Makefile.in \
24 --replace 'install-localstatelibDATA:' 'disabled:' \
25 --replace 'install-data-local:' 'disabled:' \
26 --replace 'installcheck-local:' 'disabled:'
27 substituteInPlace bus/Makefile.in \
28 --replace '$(mkinstalldirs) $(DESTDIR)$(localstatedir)/run/dbus' ':'
29 '' + /* cleanup of runtime references */ ''
30 substituteInPlace ./dbus/dbus-sysdeps-unix.c \
31 --replace 'DBUS_BINDIR "/dbus-launch"' "\"$lib/bin/dbus-launch\""
32 substituteInPlace ./tools/dbus-launch.c \
33 --replace 'DBUS_DAEMONDIR"/dbus-daemon"' '"/run/current-system/sw/bin/dbus-daemon"'
34 '';
35
36 outputs = [ "out" "dev" "lib" "doc" ];
37
38 nativeBuildInputs = [ pkgconfig ];
39 propagatedBuildInputs = [ expat ];
40 buildInputs = lib.optional stdenv.isLinux systemd
41 ++ lib.optionals x11Support [ libX11 libICE libSM ];
42 # ToDo: optional selinux?
43
44 configureFlags = [
45 "--localstatedir=/var"
46 "--sysconfdir=/etc"
47 "--with-session-socket-dir=/tmp"
48 "--with-system-pid-file=/run/dbus/pid"
49 "--with-system-socket=/run/dbus/system_bus_socket"
50 "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
51 "--with-systemduserunitdir=$(out)/etc/systemd/user"
52 "--enable-user-session"
53 "--datadir=/etc"
54 "--libexecdir=$(out)/libexec"
55 ] ++ lib.optional (!x11Support) "--without-x";
56
57 # Enable X11 autolaunch support in libdbus. This doesn't actually depend on X11
58 # (it just execs dbus-launch in dbus.tools), contrary to what the configure script demands.
59 # problems building without x11Support so disabled in that case for now
60 NIX_CFLAGS_COMPILE = lib.optionalString x11Support "-DDBUS_ENABLE_X11_AUTOLAUNCH=1";
61 NIX_CFLAGS_LINK = lib.optionalString (!stdenv.isDarwin) "-Wl,--as-needed";
62
63 enableParallelBuilding = true;
64
65 doCheck = true;
66
67 installFlags = [ "sysconfdir=$(out)/etc" "datadir=$(out)/share" ];
68
69 postInstall = ''
70 mkdir -p "$out/share/xml/dbus"
71 cp doc/*.dtd "$out/share/xml/dbus"
72 '';
73
74 # it's executed from $lib by absolute path
75 postFixup = ''
76 moveToOutput bin/dbus-launch "$lib"
77 ln -s "$lib/bin/dbus-launch" "$out/bin/"
78 '';
79
80 passthru = {
81 dbus-launch = "${self.lib}/bin/dbus-launch";
82 daemon = self.out;
83 };
84
85 meta = with stdenv.lib; {
86 description = "Simple interprocess messaging system";
87 homepage = http://www.freedesktop.org/wiki/Software/dbus/;
88 license = licenses.gpl2Plus; # most is also under AFL-2.1
89 platforms = platforms.unix;
90 };
91 };
92in self