From 38b2ba7dda92b1e7a4ba40f9b7ee06abd4b58e7f Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Tue, 16 Jun 2020 20:52:14 -0600 Subject: [PATCH] games: add wii-u-gc-adapter package and service --- .../services/hardware/wii-u-gc-adapter.nix | 40 +++++++++++++++++++ pkgs/default.nix | 1 + .../misc/drivers/wii-u-gc-adapter/default.nix | 21 ++++++++++ profiles/games/default.nix | 8 +++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 modules/services/hardware/wii-u-gc-adapter.nix create mode 100644 pkgs/misc/drivers/wii-u-gc-adapter/default.nix diff --git a/modules/services/hardware/wii-u-gc-adapter.nix b/modules/services/hardware/wii-u-gc-adapter.nix new file mode 100644 index 0000000..39b4d64 --- /dev/null +++ b/modules/services/hardware/wii-u-gc-adapter.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.services.wii-u-gc-adapter; +in { + options = { + services.wii-u-gc-adapter = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable wii-u-gc-adapter service to automatically start + when the controller adapter is plugged in. + ''; + }; + }; + }; + config = mkIf cfg.enable { + services.udev.extraRules = '' + # start wii-u-gc-adapter when plugged in + ACTION=="add", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="057e", \ + ENV{ID_MODEL_ID}=="0337", TAG+="systemd", \ + ENV{SYSTEMD_ALIAS}="/sys/subsystem/usb/wii-u-gc-adapter", \ + ENV{SYSTEMD_WANTS}+="wii-u-gc-adapter.service" + + # workaround for https://github.com/systemd/systemd/issues/7587 + ACTION=="remove", SUBSYSTEM=="usb", ENV{PRODUCT}=="57e/337/100", \ + TAG+="systemd" + ''; + + systemd.services.wii-u-gc-adapter = { + enable = true; + script = '' + ${pkgs.wii-u-gc-adapter}/bin/wii-u-gc-adapter + ''; + unitConfig = { StopWhenUnneeded = true; }; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 99b464c..759901c 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,4 +5,5 @@ final: prev: { purs = prev.callPackage ./shells/zsh/purs { }; pure = prev.callPackage ./shells/zsh/pure { }; dzvol = prev.callPackage ./applications/misc/dzvol.nix { }; + wii-u-gc-adapter = prev.callPackage ./misc/drivers/wii-u-gc-adapter { }; } diff --git a/pkgs/misc/drivers/wii-u-gc-adapter/default.nix b/pkgs/misc/drivers/wii-u-gc-adapter/default.nix new file mode 100644 index 0000000..8c20d5d --- /dev/null +++ b/pkgs/misc/drivers/wii-u-gc-adapter/default.nix @@ -0,0 +1,21 @@ +{ stdenv, fetchFromGitHub, pkgconfig, libudev, libusb, ... }: + +stdenv.mkDerivation { + name = "wii-u-gc-adapter"; + + buildInputs = [ pkgconfig libudev libusb ]; + + src = fetchFromGitHub { + owner = "ToadKing"; + repo = "wii-u-gc-adapter"; + rev = "ae6b46d7a2b32068e746f1d2d816f4b3d6a7ac80"; + hash = "sha256-Dk4jMaL5P85yxH3pDVBDNKjtGL4gRkhN5CJqZnOAshE="; + }; + + installPhase = '' + mkdir -p $out/bin + install wii-u-gc-adapter $out/bin + ''; + + hardeningDisable = [ "format" ]; +} diff --git a/profiles/games/default.nix b/profiles/games/default.nix index c0457eb..da7818e 100644 --- a/profiles/games/default.nix +++ b/profiles/games/default.nix @@ -1,5 +1,9 @@ { unstablePkgs, ... }: { - imports = [ ../graphical ./udev.nix ]; + imports = [ + ../graphical + ./udev.nix + ../../modules/services/hardware/wii-u-gc-adapter.nix + ]; environment.systemPackages = with unstablePkgs; [ retroarchBare steam @@ -8,6 +12,8 @@ qjoypad ]; + services.wii-u-gc-adapter.enable = true; + # fps games on laptop need this services.xserver.libinput.disableWhileTyping = false;