Skip to content

Commit 0cc4993

Browse files
committed
add patched usbutils
1 parent 0524c4a commit 0cc4993

4 files changed

Lines changed: 129 additions & 0 deletions

File tree

configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
"plugdev"
238238
];
239239
packages = with pkgs; [
240+
(callPackage ./custom-pkgs/usbutils/package.nix { })
240241
nix-output-monitor
241242
ffmpeg-full
242243
# davinci-resolve
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From fdf51e7bb74ba4388f5dd6151d1a94e09563011b Mon Sep 17 00:00:00 2001
2+
From: Waffle Lapkin <waffle.lapkin@gmail.com>
3+
Date: Sun, 13 Apr 2025 20:23:31 +0200
4+
Subject: [PATCH] Fix display of HID descriptors
5+
6+
The switch from hash tables to arrays + linear lookups created a bug --
7+
`names_genericstrtable` uses two variables (`h` and `t`) inconsistently
8+
in a loop, causing it to always return `NULL`, except for the first
9+
element in the array table.
10+
11+
This in turn causes everything (except "Usage Page") in the HID
12+
descriptors to be `(null)` instead of the right string.
13+
---
14+
names.c | 8 +++-----
15+
1 file changed, 3 insertions(+), 5 deletions(-)
16+
17+
diff --git a/names.c b/names.c
18+
index b47532f..6c25404 100644
19+
--- a/names.c
20+
+++ b/names.c
21+
@@ -35,11 +35,9 @@ static struct udev_hwdb *hwdb = NULL;
22+
static const char *names_genericstrtable(const struct genericstrtable *t,
23+
unsigned int idx)
24+
{
25+
- const struct genericstrtable *h;
26+
-
27+
- for (h = t; t->name; t++)
28+
- if (h->num == idx)
29+
- return h->name;
30+
+ for (; t->name; t++)
31+
+ if (t->num == idx)
32+
+ return t->name;
33+
return NULL;
34+
}
35+
36+
--
37+
2.48.1
38+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/lsusb.py b/lsusb.py
2+
index bbc4dbb..8af1b1f 100755
3+
--- a/lsusb.py
4+
+++ b/lsusb.py
5+
@@ -27,8 +27,7 @@ showwakeup = False
6+
7+
prefix = "/sys/bus/usb/devices/"
8+
usbids = [
9+
- "/usr/share/hwdata/usb.ids",
10+
- "/usr/share/usb.ids",
11+
+ "@hwdata@/share/hwdata/usb.ids",
12+
]
13+
cols = ("", "", "", "", "", "")
14+

custom-pkgs/usbutils/package.nix

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchurl,
5+
replaceVars,
6+
fetchpatch,
7+
meson,
8+
ninja,
9+
pkg-config,
10+
libusb1,
11+
hwdata,
12+
python3,
13+
}:
14+
15+
stdenv.mkDerivation rec {
16+
pname = "usbutils";
17+
version = "018";
18+
19+
src = fetchurl {
20+
url = "mirror://kernel/linux/utils/usb/usbutils/usbutils-${version}.tar.xz";
21+
hash = "sha256-g/aLWbWFR1icACZugmcYZGJ1k6tDYtjIB/UO6pI8rZM=";
22+
};
23+
24+
patches =
25+
[
26+
(replaceVars ./fix-paths.patch {
27+
inherit hwdata;
28+
})
29+
./0001-Fix-display-of-HID-descriptors.patch
30+
]
31+
++ lib.optionals stdenv.hostPlatform.isDarwin [
32+
(fetchpatch {
33+
url = "https://raw.githubusercontent.com/Homebrew/formula-patches/24a6945778381a62ecdcc1d78bcc16b9f86778c1/usbutils/portable.patch";
34+
hash = "sha256-spTkWURij4sPLoWtDaWVMIk81AS5W+qUUOQL1pAZEvs=";
35+
})
36+
];
37+
38+
nativeBuildInputs = [
39+
meson
40+
ninja
41+
pkg-config
42+
];
43+
buildInputs = [
44+
libusb1
45+
python3
46+
];
47+
48+
outputs =
49+
[
50+
"out"
51+
"man"
52+
]
53+
++ lib.optionals stdenv.hostPlatform.isLinux [
54+
"python" # uses sysfs
55+
];
56+
57+
postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
58+
moveToOutput "bin/lsusb.py" "$python"
59+
install -Dm555 usbreset -t $out/bin
60+
'';
61+
62+
meta = {
63+
homepage = "http://www.linux-usb.org/";
64+
description = "Tools for working with USB devices, such as lsusb";
65+
maintainers = with lib.maintainers; [
66+
cafkafk
67+
chuangzhu
68+
];
69+
license = with lib.licenses; [
70+
gpl2Only # manpages, usbreset
71+
gpl2Plus # most of the code
72+
];
73+
platforms = with lib.platforms; linux ++ darwin;
74+
mainProgram = "lsusb";
75+
};
76+
}

0 commit comments

Comments
 (0)