Packaging tips to reference bcc's python site-packages

I’m trying to package a handy python program ebpf-usb to monitor USB device outputs, but it uses the bcc package as a dependency. I have hacky version of a derivation working that looks like so:

{ lib
, fetchFromGitHub
, python3Packages
, bcc
, makeWrapper
}:

python3Packages.buildPythonApplication rec {
  pname = "ebpf-usb";
  version = "unstable-2022-04-03";
  format = "other";

  src = fetchFromGitHub {
    owner = "francisrstokes";
    repo = "ebpf-usb";
    rev = "3ab6f0d8c6ece51bbb5cc5e05daa4008eccd70e8";
    sha256 = "n3ttFej9sroTqAOgyAejwKT+aMt/z7HlVPV6CVGPNUQ=";
  };

  nativeBuildInputs = [ bcc makeWrapper ];

  propagatedBuildInputs = with python3Packages; [
    hexdump
  ];

  # Disable the build phase as there is no setup.py in this project
  dontBuild = true;

  installPhase = ''
    mkdir -p $out/bin
    cp ebpf-usb.py $out/bin/ebpf-usb
    chmod +x $out/bin/ebpf-usb
    BCC_SITE_PACKAGES=${bcc}/lib/python3.11/site-packages/bcc-0.28.0-py3.11.egg
    wrapProgram $out/bin/ebpf-usb \
      --prefix PYTHONPATH : $PYTHONPATH:$BCC_SITE_PACKAGES
  '';

  # no tests
  doCheck = false;

  meta = with lib; {
    description = "A Python script for USB monitoring using eBPF";
    homepage = "https://github.com/francisrstokes/ebpf-usb";
    maintainers = with maintainers; [ mevatron ];
    mainProgram = "ebpf-usb";
  };
}

This hack seems kinda brittle:

BCC_SITE_PACKAGES=${bcc}/lib/python3.11/site-packages/bcc-0.28.0-py3.11.egg
    wrapProgram $out/bin/ebpf-usb \
      --prefix PYTHONPATH : $PYTHONPATH:$BCC_SITE_PACKAGES

Is there a better way to wrap this python program to use the bcc package’s python egg file?

Also, if a project doesn’t specify a license, is the proper meta entry to not specify a license?

Thanks for any tips!

1 Like

I’m facing a similar problem. I previously used to add ${pkgs.linuxPackages.bcc}/lib/python3.10/site-packages to my $PYTHONPATH in a nix-shell. This now stopped working. Adding the full path to the bcc-0.28.0-py3.11.egg (as you are doing) seems to work. Not sure what changed. Agree, this is quite brittle.

Hey @0xB10C !

I actually went ahead and went through the MR process, and the other maintainers helped me figure out a better way to package up bcc without having to reference specific paths:

The main changes were using runHook and patching out the problematic #!/usr/bin/env header as well as being careful to keep the bcc package as a separate pythonPath in case an actual python package becomes available in the future.

Hope that helps!

1 Like