Files
nixpkgs/pkgs/os-specific/darwin/apple-source-releases/libpcap/package.nix
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

101 lines
2.5 KiB
Nix

{
lib,
apple-sdk_15,
bison,
bluez,
flex,
mkAppleDerivation,
stdenv,
stdenvNoCC,
unifdef,
# Provided for compatibility with the top-level derivation.
withBluez ? false,
withRemote ? false,
}:
let
xnu = apple-sdk_15.sourceRelease "xnu";
privateHeaders = stdenvNoCC.mkDerivation {
name = "libpcap-deps-private-headers";
nativeBuildInputs = [ unifdef ];
buildCommand = ''
mkdir -p "$out/include/net"
unifdef -x 1 -DPRIVATE -o "$out/include/net/droptap.h" '${xnu}/bsd/net/droptap.h'
unifdef -x 1 -DPRIVATE -o "$out/include/net/iptap.h" '${xnu}/bsd/net/iptap.h'
unifdef -x 1 -DPRIVATE -o "$out/include/net/pktap.h" '${xnu}/bsd/net/pktap.h'
unifdef -x 1 -DPRIVATE -o "$out/include/net/bpf.h" '${xnu}/bsd/net/bpf.h'
cat <<EOF > "$out/include/net/if.h"
#pragma once
#include_next <net/if.h>
#include <net/if_private.h>
EOF
cat <<EOF > "$out/include/net/if_private.h"
#pragma once
$(sed -n \
-e '/^#define IF_DESCSIZE\s/p' \
-e '/^struct if_descreq\s*{/,/};/p' \
'${xnu}/bsd/net/if_private.h')
EOF
mkdir -p "$out/include/sys"
cat <<EOF > "$out/include/sys/socket.h"
#pragma once
#include <sys/param.h>
#include <sys/_types/_socklen_t.h>
$(sed -n \
-e '/^#define SO_TC/p' \
'${xnu}/bsd/sys/socket_private.h')
#include_next <sys/socket.h>
EOF
cat <<EOF > "$out/include/sys/sockio.h"
#pragma once
$(sed -n \
-e '/^#define SIOCGIFDESC\s/p' \
-e '/^#define SIOCSIFDESC\s/p' \
'${xnu}/bsd/sys/sockio_private.h')
#include_next <sys/sockio.h>
EOF
'';
};
in
mkAppleDerivation {
releaseName = "libpcap";
postPatch = ''
substituteInPlace libpcap/Makefile.in \
--replace-fail '@PLATFORM_C_SRC@' '@PLATFORM_C_SRC@ pcap-darwin.c pcap-util.c pcapng.c'
substituteInPlace libpcap/pcap/pcap.h \
--replace-fail '#if PRIVATE' '#if 1'
'';
configureFlags = [
(lib.withFeatureAs true "pcap" (if stdenv.hostPlatform.isLinux then "linux" else "bpf"))
(lib.enableFeature withRemote "remote")
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ (lib.enableFeature false "universal") ];
preConfigure = ''
cd libpcap
'';
env.NIX_CFLAGS_COMPILE = "-DHAVE_PKTAP_API -I${privateHeaders}/include";
nativeBuildInputs = [
bison
flex
]
++ lib.optionals withBluez [ bluez.dev ];
meta = {
description = "Packet Capture Library (with Apple modifications)";
mainProgram = "pcap-config";
};
}