Skip to content

Instantly share code, notes, and snippets.

@pete3n
Last active December 23, 2023 19:56
Show Gist options
  • Save pete3n/4d997ee43277d31e2d7ee2a987018f5f to your computer and use it in GitHub Desktop.
Save pete3n/4d997ee43277d31e2d7ee2a987018f5f to your computer and use it in GitHub Desktop.
Nix Kismet cross-compile aarch64 on x86_64

Cross-compile Nix Kismet package for aarch64-linux on x86_64-linux

This gist shows an overlay that can be applied to the Nix Kismet package to enable cross-compiling with pkgsCross. It also provides a modified Kismet packages with the applied changes.

NOTE: This gist is now obselete, issue was resolved with this PR: NixOS/nixpkgs#276038

Cross-compile build tool emulation

QEMU is required to emulate some of the tools in the build environment (pkg-config, protoc, protoc-c). On Debian based systems install with:

sudo apt -y install qemu-user-static

And then check that aarch64 is being emulated with:

ls -l /proc/sys/fs/binfmt_misc | grep aarch64

On NixOS add:

  boot.binfmt.emulatedSystems = [ "aarch64-linux" ];

To your system config, and rebuild.

Build

Apply the kismet.nix contents to nixpkgs/applications/networking/sniffers/kismet/default.nix and build the modified package with .#pkgsCross.aarch64-multiplatform.kismet from the Nixpkgs root directory, or apply the overlay to your existing project's kismet package.

{ lib
, stdenv
, binutils
, elfutils
, fetchurl
, glib
, libcap
, libmicrohttpd
, libnl
, libpcap
, libusb1
, libwebsockets
, lm_sensors
, networkmanager
, pcre
, pkg-config
, openssl
, protobuf
, protobufc
, python3
, sqlite
, withNetworkManager ? false
, withPython ? false # Changed from default of true
, withSensors ? false
, zlib
}:
stdenv.mkDerivation rec {
pname = "kismet";
version = "2023-07-R1";
src = fetchurl {
url = "https://www.kismetwireless.net/code/${pname}-${version}.tar.xz";
hash = "sha256-8IVI4mymX6HlZ7Heu+ocpNDnIGvduWpPY5yQFxhz6Pc=";
};
postPatch = ''
substituteInPlace Makefile.in \
--replace "-m 4550" ""
'';
preConfigure = ''
export PATH=${pkg-config}/bin/:$PATH # configure will break trying to set cflag and library paths without this
'';
postConfigure = ''
sed -e 's/-o $(INSTUSR)//' \
-e 's/-g $(INSTGRP)//' \
-e 's/-g $(MANGRP)//' \
-e 's/-g $(SUIDGROUP)//' \
-i Makefile
'';
nativeBuildInputs = [
pkg-config
] ++ lib.optionals withPython [
python3
];
buildInputs = [
binutils
elfutils
libcap
libmicrohttpd
libnl
libpcap
openssl
libusb1
libwebsockets
pcre
protobuf
protobufc
sqlite
zlib
] ++ lib.optionals withNetworkManager [
networkmanager
glib
] ++ lib.optionals withSensors [
lm_sensors
];
propagatedBuildInputs = [
] ++ lib.optionals withPython [
(python3.withPackages (ps: [
ps.numpy
ps.protobuf
ps.pyserial
ps.setuptools
ps.websockets
]))
];
configureFlags = [
"--disable-wifi-coconut" # Until https://github.com/kismetwireless/kismet/issues/478
"--with-protoc=${protobuf}/bin/protoc" # configure will break with a missing protoc dependency without this
"--with-protocc=${protobufc}/bin/protoc-c" # configure will break with a missing protoc-c dependency without this
] ++ lib.optionals (!withNetworkManager) [
"--disable-libnm"
] ++ lib.optionals (!withPython) [
"--disable-python-tools"
] ++ lib.optionals (!withSensors) [
"--disable-lmsensors"
];
enableParallelBuilding = true;
meta = with lib; {
description = "Wireless network sniffer";
homepage = "https://www.kismetwireless.net/";
license = licenses.gpl3Plus;
platforms = platforms.linux;
};
}
{inputs, ...}: {
# This is an overlay example for the current kismet package that will fix the cross-compiling issues
modifications = final: prev: {
kismet = let
pname = "kismet";
version = "2023-07-R1";
in prev.kismet.overrideAttrs (oldAttrs: {
src = final.fetchurl {
url = "https://www.kismetwireless.net/code/${pname}-${version}.tar.xz";
hash = "sha256-8IVI4mymX6HlZ7Heu+ocpNDnIGvduWpPY5yQFxhz6Pc=";
};
preConfigure = ''
export PATH=${final.pkg-config}/bin/:$PATH
'';
configureFlags = oldAttrs.configureFlags ++ [
"--disable-wifi-coconut" # Until https://github.com/kismetwireless/kismet/issues/478
"--with-protoc=${final.protobuf}/bin/protoc"
"--with-protocc=${final.protobufc}/bin/protoc-c"
"--disable-libnm"
"--disable-python-tools"
"--disable-lmsensors"
];
});
};
@pete3n
Copy link
Author

pete3n commented Dec 22, 2023

I just spent the past 12 hours of my life figuring out the 3 lines of code (ok technically 5) that need to be added to the Nixpkgs kismet package source to enable cross-compiling Kismet on an x86_64-linux platform for an aarch64-linux target with nix build .#pkgsCross.aarch64-multiplatform.kismet .

First, I don't need Python so I change the default input to false. Someone else can figure out how to fix that.

For whatever reason, even though pkg-config seems to be detected fine by the configure script initially, later in the script (starting around line 11000) when it goes to configure cflags and libraries it is no longer in the path and throws a "command not found" error. This will result in a failed build starting with failed protobuf library linking and undefined reference to `protobuf_c_message_get_packed_size' and other protobuf functions.

The --with-protoc and --with-protocc flags were much easier and more obvious fixes, though I'm not sure why they can't be found when the other build inputs can be.

@pete3n
Copy link
Author

pete3n commented Dec 23, 2023

Thanks to @NickCao for helping clean up my PR to fix this: NixOS/nixpkgs#276038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment