Skip to content

feat(packaging): hermetic Nix build + -DVMLINUX_H for reproducible BPF builds - #305

Merged
ErenAri merged 1 commit into
mainfrom
feat/nix-packaging
Aug 12, 2026
Merged

feat(packaging): hermetic Nix build + -DVMLINUX_H for reproducible BPF builds#305
ErenAri merged 1 commit into
mainfrom
feat/nix-packaging

Conversation

@ErenAri

@ErenAri ErenAri commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Foundation for a NixOS/nixpkgs submission of AegisBPF, plus a reproducible-build improvement that stands on its own.

Build-system change

  • CMake -DVMLINUX_H=<path> — supply a pre-generated vmlinux.h instead of dumping the running kernel's BTF (/sys/kernel/btf/vmlinux). This makes the BPF object build hermetic — no kernel BTF at build time — which is required for sandboxed distro packaging (Nix, rpm/deb) and helps CI reproducibility. CO-RE relocates field offsets against the target kernel at load, so the object stays portable regardless of the header's source kernel. Default behaviour is unchanged (still generates vmlinux.h from the live kernel BTF when -DVMLINUX_H is not passed).

packaging/nix/

A hermetic Nix build, verified end-to-end in a nixos/nix container (nix-build → working aegisbpf version; no network, no /sys/kernel/btf):

  • package.nix — the derivation. Notable choices (each one solved a real sandbox failure): unwrapped LLVM-18 clang for the BPF object (the stdenv cc-wrapper injects -fzero-call-used-regs etc. that -target bpf rejects; LLVM 18 matches the tested clang-15/17/18 matrix and stays under the 512-byte BPF stack limit), linuxHeaders via CPATH for asm-generic/*, zstd for elfutils' libelf.pc, ENABLE_RUST_PARSER_LINK=OFF (no cargo). Absolute /etc install paths redirected under $out.
  • test-default.nix — pins nixpkgs; local nix-build entry point.
  • vmlinux.x86_64.h — checked-in CO-RE header (bpftool btf dump … format c), the same approach upstream CO-RE projects like cloudflare/ebpf_exporter use for reproducible packaging. ~166k lines; it defines the kernel types the BPF program references so the sandbox build needs no BTF.
  • README.md — build steps + rationale for each input.

Why the checked-in header

There is no reliable BTF inside a hermetic sandbox, and generating one at build time would add a fragile network fetch. Shipping the header is the accepted CO-RE/nixpkgs pattern and keeps nix-build packaging/nix/test-default.nix working for anyone who clones the repo.

Next

The NixOS/nixpkgs package (pkgs/by-name/ae/aegisbpf/) fetches a pinned commit of this repo via fetchFromGitHub and reuses this build logic; it goes up once this merges.

🤖 Generated with Claude Code

…F builds

Adds packaging/nix/ — a hermetic Nix build of the agent, the basis for a
NixOS/nixpkgs submission. Verified end-to-end in a nixos/nix container
(nix-build -> working `aegisbpf version`), no network, no /sys/kernel/btf.

Build-system change enabling it:
- CMake: new -DVMLINUX_H=<path> option supplies a pre-generated vmlinux.h
  instead of dumping the running kernel's BTF, so the BPF object builds in a
  sandbox. CO-RE keeps the object portable regardless of the header's source
  kernel. Default behaviour (generate from live BTF) is unchanged.

packaging/nix/:
- package.nix — the derivation. Unwrapped LLVM-18 clang for the BPF object
  (the stdenv cc-wrapper injects hardening flags the bpf target rejects; LLVM 18
  matches the tested clang matrix and stays under the 512-byte BPF stack limit),
  linuxHeaders via CPATH for asm-generic/*, zstd for libelf's pkg-config,
  ENABLE_RUST_PARSER_LINK=OFF (no cargo needed). Absolute /etc install paths
  redirected under $out.
- test-default.nix — pins nixpkgs; local `nix-build` entry point.
- vmlinux.x86_64.h — checked-in CO-RE header (same approach as ebpf_exporter).
- README.md — build instructions + rationale for each input.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 11, 2026 21:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ErenAri
ErenAri merged commit d0fa001 into main Aug 12, 2026
54 of 55 checks passed
@ErenAri
ErenAri deleted the feat/nix-packaging branch August 12, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants