mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-30 16:10:36 +00:00
Expose, per kernel package set, a vmlinux.h extracted from that kernel's BTF (bpftool btf dump on $dev/vmlinux). This is the pure equivalent of systemd's vmlinux-h=generated, which reads /sys/kernel/btf/vmlinux, and it lets BPF CO-RE consumers compile against the kernel they run on instead of a synthetic one. More on this: BPF CO-RE is not yet a complete solution for a stable BPF ABI. At the time of writing, CO-RE is only about offset/type relocation. The history of the kernel private ABI evolution has shown this is not enough, e.g. task_struct->utime/stime jiffies → nsecs after 4.6. Operational expertise of BPF CO-RE is not great at the moment as well: BPF verifier bugs can lead to rejection of valid programs, see https://ebpfchirp.substack.com/p/why-does-my-ebpf-program-work-on. For reminders, BTF is arch independent, so cross builds are fine.
30 lines
720 B
Nix
30 lines
720 B
Nix
{
|
|
lib,
|
|
bpftools,
|
|
kernel,
|
|
runCommand,
|
|
}:
|
|
|
|
# BTF is architecture-independent, so the extraction can run on the build
|
|
# machine even when the kernel targets another architecture.
|
|
runCommand "linux-${kernel.version}-ebpf-headers"
|
|
{
|
|
nativeBuildInputs = [ bpftools ];
|
|
|
|
passthru = {
|
|
inherit kernel;
|
|
};
|
|
|
|
meta = {
|
|
description = "vmlinux.h (kernel BTF) for BPF programs, from Linux ${kernel.version}";
|
|
homepage = "https://docs.kernel.org/bpf/btf.html";
|
|
license = lib.licenses.gpl2Only;
|
|
platforms = lib.platforms.linux;
|
|
teams = [ lib.teams.linux-kernel ];
|
|
};
|
|
}
|
|
''
|
|
mkdir -p $out
|
|
bpftool btf dump file ${kernel.dev}/vmlinux format c > $out/vmlinux.h
|
|
''
|