From c8304d130f642e6ef64bf56e4851f9510e639c49 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 18 Nov 2021 22:19:53 -0300 Subject: [PATCH] retroarch: 1.9.2 -> 1.9.13.2 The issue of non-working cores on newer versions of RetroArch was caused by the missing core metadata that is available on libretro/libretro-super repo. This also allows RetroArch to works properly, for example there is no need to load a core before loading a content: RetroArch knows each emulator to load depending on the available emulators and the file extension. To load the metadata from `/nix/store`, we need to patch the `retroarch.cfg`. Sadly this file is only updated when needed, for example, it will update if the path that it is pointing doesn't exist anymore. However, before this PR it pointed to a file located in the HOME directory, so if someone used RetroArch before they will probably have issues while loading the file. I tried to patch the configuration loader directly but the code is kinda messy and this seems very prone to breakage (while the `retroarch.cfg` file seems an stable interface). One better solution will probably be the introduction of a module that can generate `retroarch.cfg` file (since retroarch supports loading a config from `/etc/retroarch.cfg`). But this will come in a future PR. --- pkgs/misc/emulators/retroarch/default.nix | 109 +++++++++++++----- .../misc/emulators/retroarch/fix-config.patch | 26 +++++ 2 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 pkgs/misc/emulators/retroarch/fix-config.patch diff --git a/pkgs/misc/emulators/retroarch/default.nix b/pkgs/misc/emulators/retroarch/default.nix index e4c09c3c8f6c..21cbcb801616 100644 --- a/pkgs/misc/emulators/retroarch/default.nix +++ b/pkgs/misc/emulators/retroarch/default.nix @@ -1,53 +1,104 @@ -{ lib, stdenv, fetchFromGitHub, which, pkg-config, makeWrapper -, ffmpeg, libGLU, libGL, freetype, libxml2, python3 -, libobjc, AppKit, Foundation -, alsa-lib ? null -, libdrm ? null -, libpulseaudio ? null -, libv4l ? null -, libX11 ? null -, libXdmcp ? null -, libXext ? null -, libXxf86vm ? null -, mesa ? null -, SDL2 ? null -, udev ? null -, enableNvidiaCgToolkit ? false, nvidia_cg_toolkit ? null -, withVulkan ? stdenv.isLinux, vulkan-loader ? null -, wayland +{ 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"; - # FIXME: retroarch >=1.9.3 doesn't load the cores - version = "1.9.2"; + version = "1.9.13.2"; src = fetchFromGitHub { owner = "libretro"; repo = "RetroArch"; - sha256 = "sha256-Dwv0hl+d99FbVMG4KnkjO1aYfAw0m4x+zvrbyb/wOX8="; + sha256 = "sha256-fehHchn+o9QM2wIK6zYamnbFvQda32Gw0rJk8Orx00U="; rev = "v${version}"; }; - nativeBuildInputs = [ pkg-config wayland ] - ++ optional withVulkan makeWrapper; + 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 + ]; - 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 ]; + 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 ''; diff --git a/pkgs/misc/emulators/retroarch/fix-config.patch b/pkgs/misc/emulators/retroarch/fix-config.patch new file mode 100644 index 000000000000..1a71bf43cb11 --- /dev/null +++ b/pkgs/misc/emulators/retroarch/fix-config.patch @@ -0,0 +1,26 @@ +diff --git a/retroarch.cfg b/retroarch.cfg +index cdcb199c9f..08b9b1cf10 100644 +--- a/retroarch.cfg ++++ b/retroarch.cfg +@@ -681,7 +681,7 @@ + # menu_show_online_updater = true + + # If disabled, will hide the ability to update cores (and core info files) inside the menu. +-# menu_show_core_updater = true ++menu_show_core_updater = false + + # If disabled, the libretro core will keep running in the background when we + # are in the menu. +@@ -823,10 +823,10 @@ + # rgui_browser_directory = + + # Core directory for libretro core implementations. +-# libretro_directory = ++libretro_directory = @libretro_directory@ + + # Core info directory for libretro core information. +-# libretro_info_path = ++libretro_info_path = @libretro_info_path@ + + # Path to content database directory. + # content_database_path =