1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 meson,
6 ninja,
7 pkg-config,
8 gettext,
9 libxslt,
10 docbook_xsl_ns,
11 libcap,
12 libidn2,
13 iproute2,
14 apparmorRulesFromClosure,
15}:
16
17stdenv.mkDerivation rec {
18 pname = "iputils";
19 version = "20240905";
20
21 src = fetchFromGitHub {
22 owner = pname;
23 repo = pname;
24 rev = version;
25 hash = "sha256-2CjzIOe1hrW3He9DN+w+Wi2zaaMBkVEdA7dezTpkx8I=";
26 };
27
28 outputs = [
29 "out"
30 "apparmor"
31 ];
32
33 # We don't have the required permissions inside the build sandbox:
34 # /build/source/build/ping/ping: socket: Operation not permitted
35 doCheck = false;
36
37 mesonFlags =
38 [
39 "-DNO_SETCAP_OR_SUID=true"
40 "-Dsystemdunitdir=etc/systemd/system"
41 "-DINSTALL_SYSTEMD_UNITS=true"
42 "-DSKIP_TESTS=${lib.boolToString (!doCheck)}"
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 = [
48 meson
49 ninja
50 pkg-config
51 gettext
52 libxslt.bin
53 docbook_xsl_ns
54 ];
55 buildInputs = [ libcap ] ++ lib.optional (!stdenv.hostPlatform.isMusl) libidn2;
56 nativeCheckInputs = [ iproute2 ];
57
58 postInstall = ''
59 mkdir $apparmor
60 cat >$apparmor/bin.ping <<EOF
61 include <tunables/global>
62 $out/bin/ping {
63 include <abstractions/base>
64 include <abstractions/consoles>
65 include <abstractions/nameservice>
66 include "${
67 apparmorRulesFromClosure { name = "ping"; } (
68 [ libcap ] ++ lib.optional (!stdenv.hostPlatform.isMusl) libidn2
69 )
70 }"
71 include <local/bin.ping>
72 capability net_raw,
73 network inet raw,
74 network inet6 raw,
75 mr $out/bin/ping,
76 r $out/share/locale/**,
77 r @{PROC}/@{pid}/environ,
78 }
79 EOF
80 '';
81
82 meta = with lib; {
83 homepage = "https://github.com/iputils/iputils";
84 changelog = "https://github.com/iputils/iputils/releases/tag/${version}";
85 description = "Set of small useful utilities for Linux networking";
86 longDescription = ''
87 A set of small useful utilities for Linux networking including:
88
89 - arping: send ARP REQUEST to a neighbour host
90 - clockdiff: measure clock difference between hosts
91 - ping: send ICMP ECHO_REQUEST to network hosts
92 - tracepath: traces path to a network host discovering MTU along this path
93 '';
94 license = with licenses; [
95 gpl2Plus
96 bsd3
97 ];
98 platforms = platforms.linux;
99 maintainers = with maintainers; [ primeos ];
100 };
101}