about summary refs log tree commit diff
path: root/pkgs/misc/emulators/retroarch/default.nix
blob: 21cbcb801616ae1df903e015b9a63aa22159e307 (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
104
105
106
107
108
109
110
111
112
113
114
{ lib
, stdenv
, enableNvidiaCgToolkit ? false
, withVulkan ? stdenv.isLinux
, alsa-lib
, AppKit
, fetchFromGitHub
, ffmpeg
, Foundation
, freetype
, libdrm
, libGL
, libGLU
, libobjc
, libpulseaudio
, libv4l
, libX11
, libXdmcp
, libXext
, libxkbcommon
, libxml2
, libXxf86vm
, makeWrapper
, mesa
, nvidia_cg_toolkit
, pkg-config
, python3
, SDL2
, substituteAll
, udev
, vulkan-loader
, wayland
, which
}:

with lib;

let
  libretroSuperSrc = fetchFromGitHub {
    owner = "libretro";
    repo = "libretro-super";
    sha256 = "sha256-4WB6/1DDec+smhMJKLCxWb4+LQlZN8v2ik69saKixkE=";
    rev = "fa70d9843838df719623094965bd447e4db0d1b4";
  };
in
stdenv.mkDerivation rec {
  pname = "retroarch-bare";
  version = "1.9.13.2";

  src = fetchFromGitHub {
    owner = "libretro";
    repo = "RetroArch";
    sha256 = "sha256-fehHchn+o9QM2wIK6zYamnbFvQda32Gw0rJk8Orx00U=";
    rev = "v${version}";
  };

  patches = [
    # FIXME: The `retroarch.cfg` file is created once in the first run and only
    # updated when needed. However, the file may have out-of-date paths
    # In case of issues (e.g.: cores are not loading), please delete the
    # `$XDG_CONFIG_HOME/retroarch/retroarch.cfg` file
    # See: https://github.com/libretro/RetroArch/issues/13251
    ./fix-config.patch
  ];

  postPatch = ''
    substituteInPlace retroarch.cfg \
      --replace "@libretro_directory@" "$out/lib" \
      --replace "@libretro_info_path@" "$out/share/libretro/info" \
  '';

  nativeBuildInputs = [ pkg-config wayland ] ++
    optional withVulkan makeWrapper;

  buildInputs = [ ffmpeg freetype libxml2 libGLU libGL python3 SDL2 which ] ++
    optional enableNvidiaCgToolkit nvidia_cg_toolkit ++
    optional withVulkan vulkan-loader ++
    optionals stdenv.isDarwin [ libobjc AppKit Foundation ] ++
    optionals stdenv.isLinux [
      alsa-lib
      libdrm
      libpulseaudio
      libv4l
      libX11
      libXdmcp
      libXext
      libXxf86vm
      mesa
      udev
      wayland
      libxkbcommon
    ];

  enableParallelBuilding = true;

  configureFlags = lib.optionals stdenv.isLinux [ "--enable-kms" "--enable-egl" ];

  postInstall = optionalString withVulkan ''
    mkdir -p $out/share/libretro/info
    # TODO: ideally each core should have its own core information
    cp -r ${libretroSuperSrc}/dist/info/* $out/share/libretro/info
    wrapProgram $out/bin/retroarch --prefix LD_LIBRARY_PATH ':' ${vulkan-loader}/lib
  '';

  preFixup = "rm $out/bin/retroarch-cg2glsl";

  meta = {
    homepage = "https://libretro.com";
    description = "Multi-platform emulator frontend for libretro cores";
    license = licenses.gpl3Plus;
    platforms = platforms.all;
    maintainers = with maintainers; [ MP2E edwtjo matthewbauer kolbycrouch thiagokokada ];
  };
}