nct6775-pwm-udev-package.nix 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. { pkgs }:
  2. pkgs.stdenv.mkDerivation {
  3. pname = "nct6775-pwm-udev-rules";
  4. version = "1.0";
  5. dontUnpack = true;
  6. dontBuild = true;
  7. linkScript = pkgs.writeShellScript "link-nct6775-pwm" ''
  8. echo "NCT6775 udev rule triggered at $(date): devpath=$1" >> /tmp/udev-nct-debug.log
  9. # Input: DEVPATH from udev (e.g., /devices/platform/nct6775.656/hwmon/hwmon3)
  10. DEVPATH="$1"
  11. HWMON_PATH="/sys$DEVPATH"
  12. SYMLINK_DIR="/run/hwmon"
  13. # Ensure the symlink directory exists
  14. mkdir -p "$SYMLINK_DIR" || { echo "Failed to create $SYMLINK_DIR"; exit 1; }
  15. # Create symlinks for all attributes in the hwmon directory
  16. for attr in "$HWMON_PATH"/*; do
  17. if [ -e "$attr" ]; then
  18. attr_name=$(basename "$attr")
  19. echo "Linking $attr_name -> $SYMLINK_DIR/$attr_name" >> /tmp/udev-nct-debug.log
  20. ln -sf "$attr" "$SYMLINK_DIR/$attr_name" || echo "Failed to create symlink for $attr_name"
  21. else
  22. echo "No attributes found in $HWMON_PATH"
  23. fi
  24. done
  25. ls -la /sys/hwmon/ >> /tmp/udev-nct-debug.log 2>/dev/null || true
  26. '';
  27. installPhase = ''
  28. mkdir -p $out/etc/udev/rules.d
  29. cat > $out/etc/udev/rules.d/99-nct6775-pwm.rules << EOF
  30. # Create constant paths for NCT6775 PWM controls
  31. SUBSYSTEM=="hwmon", KERNEL=="hwmon[0-9]*", RUN+="$linkScript %p"
  32. EOF
  33. '';
  34. meta = with pkgs.lib; {
  35. description = "Udev rules for NCT6775 PWM device symlinks";
  36. license = licenses.mit;
  37. platforms = platforms.linux;
  38. };
  39. }