linux_xanmod: 5.11.14 -> 5.11.15
[NixPkgs.git] / pkgs / tools / networking / dnsmasq / default.nix
bloba9e4b1390a151fb2f1f3744bb3afc32f56bfb5b1
1 { lib, stdenv, fetchurl, pkg-config, dbus, nettle, fetchpatch
2 , libidn, libnetfilter_conntrack, buildPackages }:
4 with lib;
5 let
6   copts = concatStringsSep " " ([
7     "-DHAVE_IDN"
8     "-DHAVE_DNSSEC"
9   ] ++ optionals stdenv.isLinux [
10     "-DHAVE_DBUS"
11     "-DHAVE_CONNTRACK"
12   ]);
14 stdenv.mkDerivation rec {
15   pname = "dnsmasq";
16   version = "2.84";
18   src = fetchurl {
19     url = "http://www.thekelleys.org.uk/dnsmasq/${pname}-${version}.tar.xz";
20     sha256 = "sha256-YDGVxktzE3YJsH4QJK4LN/ZSsvX+Rn3OZphbPRhQBQw=";
21   };
23   postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
24     sed '1i#include <linux/sockios.h>' -i src/dhcp.c
25   '';
27   preBuild = ''
28     makeFlagsArray=("COPTS=${copts}")
29   '';
31   makeFlags = [
32     "DESTDIR="
33     "BINDIR=$(out)/bin"
34     "MANDIR=$(out)/man"
35     "LOCALEDIR=$(out)/share/locale"
36     "PKG_CONFIG=${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config"
37   ];
39   hardeningEnable = [ "pie" ];
41   postBuild = optionalString stdenv.isLinux ''
42     make -C contrib/lease-tools
43   '';
45   # XXX: Does the systemd service definition really belong here when our NixOS
46   # module can create it in Nix-land?
47   postInstall = ''
48     install -Dm644 trust-anchors.conf $out/share/dnsmasq/trust-anchors.conf
49   '' + optionalString stdenv.isDarwin ''
50     install -Dm644 contrib/MacOSX-launchd/uk.org.thekelleys.dnsmasq.plist \
51       $out/Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist
52     substituteInPlace $out/Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist \
53       --replace "/usr/local/sbin" "$out/bin"
54   '' + optionalString stdenv.isLinux ''
55     install -Dm644 dbus/dnsmasq.conf $out/share/dbus-1/system.d/dnsmasq.conf
56     install -Dm755 contrib/lease-tools/dhcp_lease_time $out/bin/dhcp_lease_time
57     install -Dm755 contrib/lease-tools/dhcp_release $out/bin/dhcp_release
58     install -Dm755 contrib/lease-tools/dhcp_release6 $out/bin/dhcp_release6
60     mkdir -p $out/share/dbus-1/system-services
61     cat <<END > $out/share/dbus-1/system-services/uk.org.thekelleys.dnsmasq.service
62     [D-BUS Service]
63     Name=uk.org.thekelleys.dnsmasq
64     Exec=$out/bin/dnsmasq -k -1
65     User=root
66     SystemdService=dnsmasq.service
67     END
68   '';
70   nativeBuildInputs = [ pkg-config ];
71   buildInputs = [ nettle libidn ]
72     ++ optionals stdenv.isLinux [ dbus libnetfilter_conntrack ];
74   meta = {
75     description = "An integrated DNS, DHCP and TFTP server for small networks";
76     homepage = "http://www.thekelleys.org.uk/dnsmasq/doc.html";
77     license = licenses.gpl2;
78     platforms = with platforms; linux ++ darwin;
79     maintainers = with maintainers; [ eelco fpletz globin ];
80   };