summaryrefslogtreecommitdiff
path: root/overlays/uhk-agent.nix
blob: 3110c8357702b76c44dfe0e05885d373b69b23f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
final: prev:
{
  uhk-agent = 
    let
      version = "1.5.14";

      image = prev.stdenv.mkDerivation {
        name = "uhk-agent-image";
        src = prev.fetchurl {
          url = "https://github.com/UltimateHackingKeyboard/agent/releases/download/v${version}/UHK.Agent-${version}-linux-x86_64.AppImage";
          hash = "sha256-D3sLjhWoeFVGgsFJo7/vsx4Dh8RsE+S6AA8z4Hsk8Ps=";
        };
        buildCommand = ''
          install -m 0644 $src $out
        '';
      };

      appimage-run' = prev.appimage-run.override {
        extraPkgs = p: with p; [
          at-spi2-core
        ];
      };
      
      runScript = prev.writeShellScript "run-uhk-agent" ''
        exec -- ${appimage-run'}/bin/appimage-run ${image}
      '';

      udevRules = prev.writeText "uhk60.rules" ''
        # Ultimate Hacking Keyboard rules
        # These are the udev rules for accessing the USB interfaces of the UHK as non-root users.
        # Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.
        SUBSYSTEM=="input", GROUP="input", MODE="0664"
        SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", MODE:="0664", GROUP="plugdev"
        KERNEL=="hidraw*", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", MODE:="0664", GROUP="plugdev"
      '';
    in prev.runCommand "uhk-agent" {} ''
        mkdir -p $out/bin $out/etc/udev/rules.d
        install -m 0755 ${runScript} $out/bin/uhk-agent
        install -m 0644 ${udevRules} $out/etc/udev/rules.d/50-uhk60.rules
      '';
}