1{
2 lib,
3 stdenv,
4 buildGoModule,
5 fetchzip,
6 gst_all_1,
7 gtkmm3,
8 hidapi,
9 makeWrapper,
10 meson,
11 ninja,
12 pkg-config,
13 python3,
14 udev,
15 udevCheckHook,
16 wrapGAppsHook3,
17}:
18
19let
20 version = "0.3.0";
21
22 src = fetchzip {
23 url = "https://github.com/carrotIndustries/usbkvm/releases/download/v${version}/usbkvm-v${version}.tar.gz";
24 hash = "sha256-urexPODXU69QfSRHtJVpoDx/6mbPcv6EQ3mR0VRHNiY=";
25 };
26
27 ms-tools-lib = buildGoModule {
28 pname = "usbkvm-ms-tools-lib";
29 inherit version src;
30
31 sourceRoot = "${src.name}/ms-tools";
32
33 vendorHash = null; # dependencies are vendored in the release tarball
34
35 buildInputs = [ hidapi ];
36
37 buildPhase = ''
38 runHook preBuild
39
40 mkdir -p $out/
41 go build -C lib/ -o $out/ -buildmode=c-archive mslib.go
42
43 runHook postBuild
44 '';
45
46 meta = {
47 homepage = "https://github.com/carrotIndustries/ms-tools";
48 description = "Program, library and reference designs to develop for MacroSilicon MS2106/MS2109/MS2130 chips";
49 license = lib.licenses.mit;
50 };
51 };
52in
53stdenv.mkDerivation {
54 pname = "usbkvm";
55 inherit version src;
56
57 # The package includes instructions to build the "mslib.{a,h}" files using a
58 # Go compiler, but that doesn't work in the Nix sandbox. We patch out this
59 # build step to instead copy those files from the Nix store:
60 patches = [
61 ./precompiled-mslib.patch
62 ];
63
64 postPatch = ''
65 substituteInPlace meson.build \
66 --replace-fail "@MSLIB_A_PRECOMPILED@" "${ms-tools-lib}/mslib.a" \
67 --replace-fail "@MSLIB_H_PRECOMPILED@" "${ms-tools-lib}/mslib.h"
68 '';
69
70 nativeBuildInputs = [
71 pkg-config
72 python3
73 meson
74 ninja
75 makeWrapper
76 wrapGAppsHook3
77 udev
78 udevCheckHook
79 ];
80
81 buildInputs = [
82 gst_all_1.gstreamer
83 gtkmm3
84 hidapi
85 ];
86
87 # Install udev rules in this package's out path:
88 mesonFlags = [
89 "-Dudevrulesdir=lib/udev/rules.d"
90 ];
91
92 postFixup =
93 let
94 GST_PLUGIN_PATH = lib.makeSearchPathOutput "lib" "lib/gstreamer-1.0" [
95 gst_all_1.gst-plugins-base
96 (gst_all_1.gst-plugins-good.override { gtkSupport = true; })
97 ];
98 in
99 lib.optionalString stdenv.hostPlatform.isLinux ''
100 wrapProgram $out/bin/usbkvm \
101 --prefix GST_PLUGIN_PATH : "${GST_PLUGIN_PATH}"
102 '';
103
104 doInstallCheck = true;
105
106 meta = {
107 homepage = "https://github.com/carrotIndustries/usbkvm";
108 description = "Open-source USB KVM (Keyboard, Video and Mouse) adapter";
109 changelog = "https://github.com/carrotIndustries/usbkvm/releases/tag/v${version}";
110 license = lib.licenses.gpl3Only;
111 maintainers = with lib.maintainers; [ lschuermann ];
112 mainProgram = "usbkvm";
113 };
114}