Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
117 lines
3.4 KiB
Nix
117 lines
3.4 KiB
Nix
{
|
|
description = "USB/IP server library and CLI tool";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
rustc
|
|
cargo
|
|
rustfmt
|
|
clippy
|
|
pkg-config
|
|
];
|
|
|
|
buildInputs = with pkgs; [
|
|
libusb1
|
|
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
|
|
udev
|
|
];
|
|
|
|
usbip-rs = pkgs.rustPlatform.buildRustPackage {
|
|
pname = "usbip-rs";
|
|
version = "0.8.0";
|
|
|
|
src = self;
|
|
|
|
cargoHash = "sha256-i2dRJ7n7J9K2PfjEUnIPS9pRXs61WUYYXAfJUmFxt/M=";
|
|
|
|
inherit nativeBuildInputs buildInputs;
|
|
|
|
buildFeatures = [ "usbip-rs/serde" ];
|
|
|
|
meta = with pkgs.lib; {
|
|
description = "USB/IP server library and CLI tool";
|
|
homepage = "https://github.com/jiegec/usbip";
|
|
license = licenses.mit;
|
|
mainProgram = "usbip-rs";
|
|
};
|
|
};
|
|
|
|
rust-nightly = rust-overlay.packages.${system}.rust-nightly;
|
|
in
|
|
{
|
|
packages = {
|
|
default = usbip-rs;
|
|
inherit usbip-rs;
|
|
};
|
|
|
|
checks = {
|
|
default = usbip-rs;
|
|
};
|
|
|
|
devShells = {
|
|
default = pkgs.mkShell {
|
|
inherit nativeBuildInputs buildInputs;
|
|
};
|
|
|
|
fuzz = pkgs.mkShell {
|
|
buildInputs = [
|
|
rust-nightly
|
|
pkgs.cargo-fuzz
|
|
pkgs.libusb1
|
|
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
|
|
pkgs.udev
|
|
];
|
|
nativeBuildInputs = [ pkgs.stdenv.cc pkgs.pkg-config ];
|
|
};
|
|
};
|
|
|
|
apps = let
|
|
fuzz-usbip = pkgs.writeShellScriptBin "fuzz-usbip" ''
|
|
set -euo pipefail
|
|
export PATH="${rust-nightly}/bin:${pkgs.cargo-fuzz}/bin:${pkgs.stdenv.cc}/bin:${pkgs.pkg-config}/bin:$PATH"
|
|
export PKG_CONFIG_PATH="${pkgs.libusb1.dev}/lib/pkgconfig''${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux '':${pkgs.udev.dev}/lib/pkgconfig''}
|
|
cd "$(${pkgs.git}/bin/git rev-parse --show-toplevel)/lib"
|
|
if [ $# -eq 0 ]; then
|
|
cargo fuzz list
|
|
else
|
|
target="$1"
|
|
shift
|
|
fork=0
|
|
args=()
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--fork=*) fork=''${arg#--fork=} ;;
|
|
*) args+=("$arg") ;;
|
|
esac
|
|
done
|
|
if [ "$fork" -gt 0 ]; then
|
|
while true; do
|
|
cargo fuzz run "$target" -- -max_len=1048576 "-fork=$fork" "''${args[@]}" || true
|
|
echo "--- fuzzer exited, restarting (artifacts saved) ---"
|
|
done
|
|
else
|
|
cargo fuzz run "$target" -- -max_len=1048576 "''${args[@]}"
|
|
fi
|
|
fi
|
|
'';
|
|
in {
|
|
fuzz-usbip = {
|
|
type = "app";
|
|
program = "${fuzz-usbip}/bin/fuzz-usbip";
|
|
};
|
|
};
|
|
});
|
|
}
|