1 { lib, stdenv, fetchurl, pkg-config, nettle
2 , libidn, libnetfilter_conntrack, nftables, buildPackages
3 , dbusSupport ? stdenv.hostPlatform.isLinux
9 copts = lib.concatStringsSep " " ([
12 ] ++ lib.optionals dbusSupport [
14 ] ++ lib.optionals stdenv.hostPlatform.isLinux [
19 stdenv.mkDerivation rec {
24 url = "https://www.thekelleys.org.uk/dnsmasq/${pname}-${version}.tar.xz";
25 hash = "sha256-jlAwm9g3v+yWSagS4GbAm2mItz10m30pPAbFfUahCeQ=";
28 postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
29 sed '1i#include <linux/sockios.h>' -i src/dhcp.c
33 makeFlagsArray=("COPTS=${copts}")
40 "LOCALEDIR=$(out)/share/locale"
41 "PKG_CONFIG=${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config"
44 hardeningEnable = [ "pie" ];
46 postBuild = lib.optionalString stdenv.hostPlatform.isLinux ''
47 make -C contrib/lease-tools
50 # XXX: Does the systemd service definition really belong here when our NixOS
51 # module can create it in Nix-land?
53 install -Dm644 trust-anchors.conf $out/share/dnsmasq/trust-anchors.conf
54 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
55 install -Dm644 contrib/MacOSX-launchd/uk.org.thekelleys.dnsmasq.plist \
56 $out/Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist
57 substituteInPlace $out/Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist \
58 --replace "/usr/local/sbin" "$out/bin"
59 '' + lib.optionalString stdenv.hostPlatform.isLinux ''
60 install -Dm755 contrib/lease-tools/dhcp_lease_time $out/bin/dhcp_lease_time
61 install -Dm755 contrib/lease-tools/dhcp_release $out/bin/dhcp_release
62 install -Dm755 contrib/lease-tools/dhcp_release6 $out/bin/dhcp_release6
64 '' + lib.optionalString dbusSupport ''
65 install -Dm644 dbus/dnsmasq.conf $out/share/dbus-1/system.d/dnsmasq.conf
66 mkdir -p $out/share/dbus-1/system-services
67 cat <<END > $out/share/dbus-1/system-services/uk.org.thekelleys.dnsmasq.service
69 Name=uk.org.thekelleys.dnsmasq
70 Exec=$out/bin/dnsmasq -k -1
72 SystemdService=dnsmasq.service
76 nativeBuildInputs = [ pkg-config ];
77 buildInputs = [ nettle libidn ]
78 ++ lib.optionals dbusSupport [ dbus ]
79 ++ lib.optionals stdenv.hostPlatform.isLinux [ libnetfilter_conntrack nftables ];
82 prometheus-exporter = nixosTests.prometheus-exporters.dnsmasq;
84 # these tests use dnsmasq incidentally
85 inherit (nixosTests) dnscrypt-proxy2;
86 kubernetes-dns-single = nixosTests.kubernetes.dns-single-node;
87 kubernetes-dns-multi = nixosTests.kubernetes.dns-multi-node;
91 description = "Integrated DNS, DHCP and TFTP server for small networks";
92 homepage = "https://www.thekelleys.org.uk/dnsmasq/doc.html";
93 license = licenses.gpl2Only;
94 mainProgram = "dnsmasq";
95 platforms = with platforms; linux ++ darwin;
96 maintainers = with maintainers; [ fpletz globin ];