20 # By default unbound will not be built with systemd support. Unbound is a very
21 # common dependency. The transitive dependency closure of systemd also
23 # Since most (all?) (lib)unbound users outside of the unbound daemon usage do
24 # not need the systemd integration it is likely best to just default to no
25 # systemd integration.
26 # For the daemon use-case, that needs to notify systemd, use `unbound-with-systemd`.
30 # optionally support DNS-over-HTTPS as a server
33 , withDNSCrypt ? false
37 # Avoid .lib depending on lib.getLib openssl
38 # The build gets a little hacky, so in some cases we disable this approach.
39 , withSlimLib ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isMusl && !withDNSTAP
40 # enable support for python plugins in unbound: note this is distinct from pyunbound
41 # see https://unbound.docs.nlnetlabs.nl/en/latest/developer/python-modules.html
42 , withPythonModule ? false
43 , withLto ? !stdenv.hostPlatform.isStatic && !stdenv.hostPlatform.isMinGW
44 , withMakeWrapper ? !stdenv.hostPlatform.isMinGW
51 stdenv.mkDerivation (finalAttrs: {
56 url = "https://nlnetlabs.nl/downloads/unbound/unbound-${finalAttrs.version}.tar.gz";
57 hash = "sha256-59yn1rD4G9+m+mTr8QU7WpmaWukniofvGCQlBn6hRSE=";
60 outputs = [ "out" "lib" "man" ]; # "dev" would only split ~20 kB
63 lib.optionals withMakeWrapper [ makeWrapper ]
64 ++ lib.optionals withDNSTAP [ protobufc ]
66 ++ lib.optionals withPythonModule [ swig ];
68 buildInputs = [ openssl nettle expat libevent ]
69 ++ lib.optionals withSystemd [ systemd ]
70 ++ lib.optionals withDoH [ libnghttp2 ]
71 ++ lib.optionals withPythonModule [ python ];
73 enableParallelBuilding = true;
76 "--with-ssl=${openssl.dev}"
77 "--with-libexpat=${expat.dev}"
78 "--with-libevent=${libevent.dev}"
79 "--localstatedir=/var"
81 "--sbindir=\${out}/bin"
82 "--with-rootkey-file=${dns-root-data}/root.key"
85 ] ++ lib.optionals (!withLto) [
87 ] ++ lib.optionals withSystemd [
89 ] ++ lib.optionals withPythonModule [
91 ] ++ lib.optionals withDoH [
92 "--with-libnghttp2=${libnghttp2.dev}"
93 ] ++ lib.optionals withECS [
95 ] ++ lib.optionals withDNSCrypt [
97 "--with-libsodium=${symlinkJoin { name = "libsodium-full"; paths = [ libsodium.dev libsodium.out ]; }}"
98 ] ++ lib.optionals withDNSTAP [
100 ] ++ lib.optionals withTFO [
101 "--enable-tfo-client"
102 "--enable-tfo-server"
103 ] ++ lib.optionals withRedis [
105 "--with-libhiredis=${hiredis}"
108 PROTOC_C = lib.optionalString withDNSTAP "${protobufc}/bin/protoc-c";
110 # Remove references to compile-time dependencies that are included in the configure flags
112 inherit (builtins) storeDir;
114 sed -E '/CONFCMDLINE/ s;${storeDir}/[a-z0-9]{32}-;${storeDir}/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-;g' -i config.h
117 nativeCheckInputs = [ bison ];
121 postPatch = lib.optionalString withPythonModule ''
122 substituteInPlace Makefile.in \
123 --replace "\$(DESTDIR)\$(PYTHON_SITE_PKG)" "$out/${python.sitePackages}"
126 installFlags = [ "configfile=\${out}/etc/unbound/unbound.conf" ];
129 make unbound-event-install
130 '' + lib.optionalString withMakeWrapper ''
131 wrapProgram $out/bin/unbound-control-setup \
132 --prefix PATH : ${lib.makeBinPath [ openssl ]}
133 '' + lib.optionalString (withMakeWrapper && withPythonModule) ''
134 wrapProgram $out/bin/unbound \
135 --prefix PYTHONPATH : "$out/${python.sitePackages}" \
136 --argv0 $out/bin/unbound
139 preFixup = lib.optionalString withSlimLib
140 # Build libunbound again, but only against nettle instead of openssl.
141 # This avoids gnutls.out -> unbound.lib -> lib.getLib openssl.
143 configureFlags="$configureFlags --with-nettle=${nettle.dev} --with-libunbound-only"
146 if [ -n "$doCheck" ]; then
151 # get rid of runtime dependencies on $dev outputs
152 + ''substituteInPlace "$lib/lib/libunbound.la" ''
153 + lib.concatMapStrings
154 (pkg: lib.optionalString (pkg ? dev) " --replace '-L${pkg.dev}/lib' '-L${pkg.out}/lib' --replace '-R${pkg.dev}/lib' '-R${pkg.out}/lib'")
155 (builtins.filter (p: p != null) finalAttrs.buildInputs);
159 nixos-test = nixosTests.unbound;
160 nixos-test-exporter = nixosTests.prometheus-exporters.unbound;
164 description = "Validating, recursive, and caching DNS resolver";
165 license = licenses.bsd3;
166 homepage = "https://www.unbound.net";
167 maintainers = lib.teams.helsinki-systems.members;
168 platforms = platforms.unix ++ platforms.windows;