1{ fetchurl
2, fetchpatch
3, lib
4, stdenv
5, pkg-config
6, libdaemon
7, dbus
8, perlPackages
9, libpcap
10, expat
11, gettext
12, glib
13, libiconv
14, libevent
15, nixosTests
16, gtk3Support ? false
17, gtk3
18, qt5
19, qt5Support ? false
20, withLibdnssdCompat ? false
21, python ? null
22, withPython ? false
23}:
24
25stdenv.mkDerivation rec {
26 pname = "avahi${lib.optionalString withLibdnssdCompat "-compat"}";
27 version = "0.8";
28
29 src = fetchurl {
30 url = "https://github.com/lathiat/avahi/releases/download/v${version}/avahi-${version}.tar.gz";
31 sha256 = "1npdixwxxn3s9q1f365x9n9rc5xgfz39hxf23faqvlrklgbhj0q6";
32 };
33
34 outputs = [ "out" "dev" "man" ];
35
36 patches = [
37 # CVE-2021-36217 / CVE-2021-3502
38 (fetchpatch {
39 name = "CVE-2021-3502.patch";
40 url = "https://github.com/lathiat/avahi/commit/9d31939e55280a733d930b15ac9e4dda4497680c.patch";
41 sha256 = "sha256-BXWmrLWUvDxKPoIPRFBpMS3T4gijRw0J+rndp6iDybU=";
42 })
43 # CVE-2021-3468
44 (fetchpatch {
45 name = "CVE-2021-3468.patch";
46 url = "https://github.com/lathiat/avahi/commit/447affe29991ee99c6b9732fc5f2c1048a611d3b.patch";
47 sha256 = "sha256-qWaCU1ZkCg2PmijNto7t8E3pYRN/36/9FrG8okd6Gu8=";
48 })
49 (fetchpatch {
50 name = "CVE-2023-1981.patch";
51 url = "https://github.com/lathiat/avahi/commit/a2696da2f2c50ac43b6c4903f72290d5c3fa9f6f.patch";
52 sha256 = "sha256-BEYFGCnQngp+OpiKIY/oaKygX7isAnxJpUPCUvg+efc=";
53 })
54 ];
55
56 depsBuildBuild = [
57 pkg-config
58 ];
59
60 nativeBuildInputs = [
61 pkg-config
62 gettext
63 glib
64 ];
65
66 buildInputs = [
67 libdaemon
68 dbus
69 glib
70 expat
71 libiconv
72 libevent
73 ] ++ (with perlPackages; [
74 perl
75 XMLParser
76 ]) ++ lib.optionals stdenv.isFreeBSD [
77 libpcap
78 ] ++ lib.optionals gtk3Support [
79 gtk3
80 ] ++ lib.optionals qt5Support [
81 qt5
82 ];
83
84 propagatedBuildInputs = lib.optionals withPython (with python.pkgs; [
85 python
86 pygobject3
87 dbus-python
88 ]);
89
90 configureFlags = [
91 "--disable-gdbm"
92 "--disable-mono"
93 # Use non-deprecated path https://github.com/lathiat/avahi/pull/376
94 "--with-dbus-sys=${placeholder "out"}/share/dbus-1/system.d"
95 (lib.enableFeature gtk3Support "gtk3")
96 (lib.enableFeature qt5Support "qt5")
97 (lib.enableFeature withPython "python")
98 "--localstatedir=/var"
99 "--runstatedir=/run"
100 "--sysconfdir=/etc"
101 "--with-distro=${with stdenv.hostPlatform; if isBSD then parsed.kernel.name else "none"}"
102 # A systemd unit is provided by the avahi-daemon NixOS module
103 "--with-systemdsystemunitdir=no"
104 ] ++ lib.optionals withLibdnssdCompat [
105 "--enable-compat-libdns_sd"
106 ] ++ lib.optionals stdenv.isDarwin [
107 # autoipd won't build on darwin
108 "--disable-autoipd"
109 ];
110
111 installFlags = [
112 # Override directories to install into the package.
113 # Replace with runstatedir once is merged https://github.com/lathiat/avahi/pull/377
114 "avahi_runtime_dir=${placeholder "out"}/run"
115 "sysconfdir=${placeholder "out"}/etc"
116 ];
117
118 preBuild = lib.optionalString stdenv.isDarwin ''
119 sed -i '20 i\
120 #define __APPLE_USE_RFC_2292' \
121 avahi-core/socket.c
122 '';
123
124 postInstall =
125 # Maintain compat for mdnsresponder
126 lib.optionalString withLibdnssdCompat ''
127 ln -s avahi-compat-libdns_sd/dns_sd.h "$dev/include/dns_sd.h"
128 '';
129
130 passthru.tests = {
131 smoke-test = nixosTests.avahi;
132 smoke-test-resolved = nixosTests.avahi-with-resolved;
133 };
134
135 meta = with lib; {
136 description = "mDNS/DNS-SD implementation";
137 homepage = "http://avahi.org";
138 license = licenses.lgpl2Plus;
139 platforms = platforms.unix;
140 maintainers = with maintainers; [ lovek323 globin ];
141
142 longDescription = ''
143 Avahi is a system which facilitates service discovery on a local
144 network. It is an implementation of the mDNS (for "Multicast
145 DNS") and DNS-SD (for "DNS-Based Service Discovery")
146 protocols.
147 '';
148 };
149}