about summary refs log tree commit diff
path: root/nixpkgs/pkgs/games/gimx/default.nix
blob: 4173ac0cc2d6d171508b6db72e069936871ef509 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{ stdenv, lib, fetchFromGitHub, fetchpatch
, makeWrapper, curl, libusb1, xorg, libxml2
, ncurses5, bluez, libmhash, gimxPdpGamepad ? false }:

let
  gimx-config = fetchFromGitHub {
    owner = "matlo";
    repo = "GIMX-configurations";
    rev = "c20300f24d32651d369e2b27614b62f4b856e4a0";
    sha256 = "02wcjk8da188x7y0jf3p0arjdh9zbb0lla3fxdb28b1xyybfvx5p";
  };

in stdenv.mkDerivation rec {
  pname = "gimx";
  version = "unstable-2021-08-31";

  src = fetchFromGitHub {
    owner = "matlo";
    repo = "GIMX";
    rev = "58d2098dce75ed4c90ae649460d3a7a150f4ef0a";
    fetchSubmodules = true;
    sha256 = "05kdv2qqr311c2p76hdlgvrq7b04vcpps5c80zn8b8l7p831ilgz";
  };

  patches = [
    ./conf.patch

    # gcc-13 build fixes:
    #   https://github.com/matlo/GIMX/pull/705
    (fetchpatch {
      name = "gcc-13-headers.patch";
      url = "https://github.com/matlo/GIMX/commit/4525dff4d9af672116d8c6c182707f2ad6295b2d.patch";
      hash = "sha256-LkswnFsxqADooa09yO7Yf0AbxTrGfjBObyv/6FQJvRs=";
    })
    (fetchpatch {
      name = "gcc-13-protos.patch";
      url = "https://github.com/matlo/GIMX/commit/f11855fcb8bd9d0cb9c94871b4111ddfd5b610df.patch";
      hash = "sha256-JL67UUsEyPcOuaimJtMviiGLGghuq9665Lg1QuiaWUU=";
    })
  ];

  nativeBuildInputs = [ makeWrapper ];
  buildInputs = [
    curl libusb1 bluez libxml2 ncurses5 libmhash
    xorg.libX11 xorg.libXi xorg.libXext
  ];

  postPatch = lib.optionals gimxPdpGamepad ''
    substituteInPlace ./shared/gimxcontroller/include/x360.h \
      --replace "0x045e" "0x0e6f" --replace "0x028e" "0x0213"
    substituteInPlace ./loader/firmware/EMU360.hex \
      --replace "1B210001" "1B211001" \
      --replace "09210001" "09211001" \
      --replace "5E048E021001" "6F0E13020001"
  '';

  makeFlags = [ "build-core" ];

  env.NIX_CFLAGS_COMPILE = toString [
    # Needed with GCC 12
    "-Wno-error=address"
    "-Wno-error=deprecated-declarations"
    "-Wno-error=use-after-free"
  ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out
    substituteInPlace ./core/Makefile --replace "chmod ug+s" "echo"

    export DESTDIR="$out"
    make install-shared install-core
    mv $out/usr/lib $out/lib
    mv $out/usr/bin $out/bin
    rmdir $out/usr

    runHook postInstall
  '';

  postInstall = ''
    mkdir -p $out/share
    cp -r ./loader/firmware $out/share/firmware
    cp -r ${gimx-config}/Linux $out/share/config
    cp -r ${./custom} $out/share/custom

    makeWrapper $out/bin/gimx $out/bin/gimx-dualshock4 \
      --set GIMXCONF 1 --add-flags "--nograb" --add-flags "-p /dev/ttyUSB0" \
      --add-flags "-c $out/share/custom/Dualshock4.xml"

    makeWrapper $out/bin/gimx $out/bin/gimx-xboxonepad \
      --set GIMXCONF 1 --add-flags "--nograb" --add-flags "-p /dev/ttyUSB0" \
      --add-flags "-c $out/share/config/XOnePadUsb.xml"
  '';

  meta = with lib; {
    homepage = "https://github.com/matlo/GIMX";
    description = "Game Input Multiplexer";
    license = licenses.gpl3Only;
    platforms = platforms.linux;
    maintainers = with maintainers; [ bb2020 ];
  };
}