1{ lib, stdenv, fetchFromGitHub
2, meson, ninja, pkg-config, gettext, libxslt, docbook_xsl_ns
3, libcap, libidn2
4, iproute2
5, apparmorRulesFromClosure
6}:
7
8let
9 version = "20210722";
10 sunAsIsLicense = {
11 fullName = "AS-IS, SUN MICROSYSTEMS license";
12 url = "https://github.com/iputils/iputils/blob/s${version}/rdisc.c";
13 };
14in stdenv.mkDerivation rec {
15 pname = "iputils";
16 inherit version;
17
18 src = fetchFromGitHub {
19 owner = pname;
20 repo = pname;
21 rev = version;
22 sha256 = "139fyifsjm0i012rhcx3ra3pxx2wxh77dfd551d8lgiv2mqd742j";
23 };
24
25 postPatch = lib.optionalString (!doCheck) ''
26 # There isn't a Meson option for this yet:
27 sed -i '/##### TESTS #####/q' ping/meson.build
28 '';
29
30 outputs = ["out" "apparmor"];
31
32 # We don't have the required permissions inside the build sandbox:
33 # /build/source/build/ping/ping: socket: Operation not permitted
34 doCheck = false;
35
36 mesonFlags = [
37 "-DBUILD_RARPD=true"
38 "-DBUILD_TRACEROUTE6=true"
39 "-DBUILD_TFTPD=true"
40 "-DNO_SETCAP_OR_SUID=true"
41 "-Dsystemdunitdir=etc/systemd/system"
42 "-DINSTALL_SYSTEMD_UNITS=true"
43 ]
44 # Disable idn usage w/musl (https://github.com/iputils/iputils/pull/111):
45 ++ lib.optional stdenv.hostPlatform.isMusl "-DUSE_IDN=false";
46
47 nativeBuildInputs = [ meson ninja pkg-config gettext libxslt.bin docbook_xsl_ns ];
48 buildInputs = [ libcap ]
49 ++ lib.optional (!stdenv.hostPlatform.isMusl) libidn2;
50 checkInputs = [ iproute2 ];
51
52 postInstall = ''
53 mkdir $apparmor
54 cat >$apparmor/bin.ping <<EOF
55 include <tunables/global>
56 $out/bin/ping {
57 include <abstractions/base>
58 include <abstractions/consoles>
59 include <abstractions/nameservice>
60 include "${apparmorRulesFromClosure { name = "ping"; }
61 ([libcap] ++ lib.optional (!stdenv.hostPlatform.isMusl) libidn2)}"
62 include <local/bin.ping>
63 capability net_raw,
64 network inet raw,
65 network inet6 raw,
66 mr $out/bin/ping,
67 r $out/share/locale/**,
68 r @{PROC}/@{pid}/environ,
69 }
70 EOF
71 '';
72
73 meta = with lib; {
74 description = "A set of small useful utilities for Linux networking";
75 inherit (src.meta) homepage;
76 changelog = "https://github.com/iputils/iputils/releases/tag/s${version}";
77 license = with licenses; [ gpl2Plus bsd3 sunAsIsLicense ];
78 platforms = platforms.linux;
79 maintainers = with maintainers; [ primeos lheckemann ];
80
81 longDescription = ''
82 A set of small useful utilities for Linux networking including:
83
84 arping
85 clockdiff
86 ninfod
87 ping
88 rarpd
89 rdisc
90 tftpd
91 tracepath
92 traceroute6
93 '';
94 };
95}