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