Commit bcf9a243 authored by Brenton Simpson's avatar Brenton Simpson
Browse files

handheld-daemon: init at 0.2.7

parent 5f5210aa
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ In addition to numerous new and upgraded packages, this release has the followin

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

- [Handheld Daemon](https://github.com/hhd-dev/hhd), support for gaming handhelds like the Legion Go, ROG Ally, and GPD Win. Available as [services.handheldDaemon](#opt-services.handheldDaemon.enable).

- [Guix](https://guix.gnu.org), a functional package manager inspired by Nix. Available as [services.guix](#opt-services.guix.enable).

- [maubot](https://github.com/maubot/maubot), a plugin-based Matrix bot framework. Available as [services.maubot](#opt-services.maubot.enable).
+1 −0
Original line number Diff line number Diff line
@@ -532,6 +532,7 @@
  ./services/hardware/fancontrol.nix
  ./services/hardware/freefall.nix
  ./services/hardware/fwupd.nix
  ./services/hardware/handheld-daemon.nix
  ./services/hardware/hddfancontrol.nix
  ./services/hardware/illum.nix
  ./services/hardware/interception-tools.nix
+43 −0
Original line number Diff line number Diff line
{ config
, lib
, pkgs
, ...
}:
with lib; let
  cfg = config.services.handheldDaemon;
in
{
  options.services.handheldDaemon = {
    enable = mkEnableOption "Enable Handheld Daemon";

    user = mkOption {
      type = types.str;
      description = lib.mdDoc ''
        The user to run Handheld Daemon with.
      '';
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ pkgs.handheld-daemon ];
    services.udev.packages = [ pkgs.handheld-daemon ];
    systemd.packages = [ pkgs.handheld-daemon ];

    systemd.services.handheldDaemon = {
      description = "Handheld Daemon";

      wantedBy = [ "multi-user.target" ];

      restartIfChanged = true;

      serviceConfig = {
        ExecStart = "${ pkgs.handheld-daemon }/bin/hhd --user ${ cfg.user }";
        Nice = "-12";
        Restart = "on-failure";
        RestartSec = "10";
      };
    };
  };

  meta.maintainers = [ maintainers.appsforartists ];
}
+54 −0
Original line number Diff line number Diff line
{ config
, fetchFromGitHub
, hidapi
, lib
, python3
,
}:
python3.pkgs.buildPythonApplication rec {
  pname = "handheld-daemon";
  version = "0.2.7";
  format = "pyproject";

  src = fetchFromGitHub {
    owner = "hhd-dev";
    repo = "hhd";
    rev = "ccae6b207cadfbdaef292270c4fc6c855f71ba03";
    hash = "sha256-+tyiXOvZXLbomhgFRKUNKGbkkkOxQKdk/kjeWZ4pvO0=";
  };

  pythonPath = with python3.pkgs; [
    evdev
    pyyaml
    rich
  ];

  nativeBuildInputs = with python3.pkgs; [
    setuptools
  ];

  propagatedBuildInputs = [
    hidapi
  ];

  # handheld-daemon contains a fork of the python module `hid`, so this hook
  # is borrowed from the `hid` derivation.
  postPatch = ''
    hidapi=${ hidapi }/lib/
    test -d $hidapi || { echo "ERROR: $hidapi doesn't exist, please update/fix this build expression."; exit 1; }
    sed -i -e "s|libhidapi|$hidapi/libhidapi|" src/hhd/controller/lib/hid.py
  '';

  postInstall = ''
    install -Dm644 $src/usr/lib/udev/rules.d/83-hhd.rules -t $out/lib/udev/rules.d/
  '';

  meta = with lib; {
    homepage = "https://github.com/hhd-dev/hhd/";
    description = "Linux support for gaming handhelds";
    platforms = platforms.linux;
    license = licenses.mit;
    maintainers = with maintainers; [ appsforartists ];
    mainProgram = "hhd";
  };
}