1{ stdenv, lib, fetchzip, kernel }:
2
3stdenv.mkDerivation rec {
4 pname = "ch9344";
5 version = "1.9";
6
7 src = fetchzip {
8 name = "CH9344SER_LINUX.zip";
9 url = "https://www.wch.cn/downloads/file/386.html#CH9344SER_LINUX.zip";
10 hash = "sha256-g55ftAfjKKlUFzGhI1a/O7Eqbz6rkGf1vWuEJjBZxBE=";
11 };
12
13 patches = lib.optionals (lib.versionAtLeast kernel.modDirVersion "6.1") [
14 # https://github.com/torvalds/linux/commit/a8c11c1520347be74b02312d10ef686b01b525f1
15 ./fix-incompatible-pointer-types.patch
16 ] ++ lib.optionals (lib.versionAtLeast kernel.modDirVersion "6.3") [
17 # https://github.com/torvalds/linux/commit/5d420399073770134d2b03e004b2c0201c7fa26f
18 ./fix-incompatible-pointer-types_6_3.patch
19 ];
20
21 sourceRoot = "${src.name}/driver";
22 hardeningDisable = [ "pic" ];
23 nativeBuildInputs = kernel.moduleBuildDependencies;
24
25 preBuild = ''
26 substituteInPlace Makefile --replace "KERNELDIR :=" "KERNELDIR ?="
27 '';
28
29 makeFlags = [
30 "KERNELDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
31 ];
32
33 installPhase = ''
34 runHook preInstall
35 install -D ch9344.ko $out/lib/modules/${kernel.modDirVersion}/usb/serial/ch9344.ko
36 runHook postInstall
37 '';
38
39 meta = with lib; {
40 homepage = "http://www.wch-ic.com/";
41 downloadPage = "https://www.wch.cn/downloads/CH9344SER_LINUX_ZIP.html";
42 description = "WCH CH9344/CH348 UART driver";
43 longDescription = ''
44 A kernel module for WinChipHead CH9344/CH348 USB To Multi Serial Ports controller.
45 '';
46 # Archive contains no license.
47 license = licenses.unfree;
48 platforms = platforms.linux;
49 maintainers = with maintainers; [ MakiseKurisu ];
50 };
51}