{ config, lib, pkgs, ... }: let pivccu-modules = config.boot.kernelPackages.callPackage ({ stdenv, fetchFromGitHub, kernel }: stdenv.mkDerivation rec { pname = "pivccu-modules"; version = "master"; src = fetchFromGitHub { owner = "alexreinert"; repo = "piVCCU"; rev = "master"; # Ensure this matches the hash you got earlier sha256 = "sha256-cXvrLcASU/2nsfJBf+cVtC4JnAq4G5JFzcFgj5ztThc="; }; # Set the source root to the kernel subdirectory sourceRoot = "${src.name}/kernel"; hardeningDisable = [ "pic" "format" ]; nativeBuildInputs = kernel.moduleBuildDependencies; # 1. FORCE delete the upstream Makefile (which causes the build error) # 2. Create a clean Makefile that only builds the modules we need postPatch = '' rm -f Makefile echo "obj-m += eq3_char_loop.o plat_eq3ccu2.o" > Makefile ''; # 3. Explicitly point to the kernel build directory makeFlags = [ "KERNEL_DIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" "INSTALL_MOD_PATH=$(out)" "M=$(pwd)" "modules" ]; # 4. Use the kernel build system to compile the modules buildPhase = '' make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build M=$(pwd) modules ''; installPhase = '' make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build M=$(pwd) INSTALL_MOD_PATH=$out modules_install ''; }) {}; in { boot.extraModulePackages = [ pivccu-modules ]; # Load the modules required for the USB stick boot.kernelModules = [ "cp210x" "eq3_char_loop" "plat_eq3ccu2" ]; # Udev rules for HmIP-RFUSB services.udev.extraRules = '' # 1. FORCE BINDING: Tell cp210x to handle the HmIP-RFUSB (1b1f:c020) # We use 'sh -c echo' because 'new_id' is a virtual file that tells the driver to accept new IDs. ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1b1f", ATTR{idProduct}=="c020", \ RUN+="${pkgs.kmod}/bin/modprobe cp210x", \ RUN+="${pkgs.bash}/bin/sh -c 'echo 1b1f c020 > /sys/bus/usb-serial/drivers/cp210x/new_id'" # 2. CREATE SYMLINK: Once the driver binds, a ttyUSBx device appears. # We symlink it to /dev/raw-uart and set permissions. SUBSYSTEM=="tty", ATTRS{idVendor}=="1b1f", ATTRS{idProduct}=="c020", SYMLINK+="raw-uart", OWNER="root", GROUP="root", MODE="0666" # 3. USB PERMISSIONS: Ensure the raw USB device is also accessible SUBSYSTEM=="usb", ATTRS{idVendor}=="1b1f", ATTRS{idProduct}=="c020", MODE="0666" ''; }