Commit cb5179db authored by Thiago Kenji Okada's avatar Thiago Kenji Okada
Browse files

retroarch: refactor wrapper to use symlinkJoin

parent 64ae43e9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -170,7 +170,6 @@ stdenv.mkDerivation rec {
    mainProgram = "retroarch";
    # FIXME: error while building in macOS:
    # "Undefined symbols for architecture <arch>"
    # See also retroarch/wrapper.nix that is also broken in macOS
    broken = stdenv.isDarwin;
  };
}
+37 −27
Original line number Diff line number Diff line
{ stdenv, lib, makeWrapper, retroarch, cores ? [ ] }:

stdenv.mkDerivation {
  pname = "retroarch";
  version = lib.getVersion retroarch;
{ lib
, stdenv
, makeWrapper
, retroarch
, symlinkJoin
, cores ? [ ]
}:

let
  coresPath = lib.lists.unique (map (c: c.libretroCore) cores);
  wrapperArgs = lib.strings.escapeShellArgs
    (lib.lists.flatten
      (map (corePath: [ "--add-flags" "-L ${placeholder "out" + corePath}" ]) coresPath));
in
symlinkJoin {
  name = "retroarch-with-cores-${lib.getVersion retroarch}";

  paths = [ retroarch ] ++ cores;

  nativeBuildInputs = [ makeWrapper ];

  buildCommand = ''
    mkdir -p $out/lib
    for coreDir in $cores; do
      ln -s $coreDir/* $out/lib/.
    done

    ln -s -t $out ${retroarch}/share

    if [ -d ${retroarch}/Applications ]; then
      ln -s -t $out ${retroarch}/Applications
    fi
  passthru = {
    inherit cores;
    unwrapped = retroarch;
  };

  postBuild = ''
    # remove core specific binaries
    find $out/bin -name 'retroarch-*' -delete
    # wrapProgram can't operate on symlinks
    rm $out/bin/retroarch
    makeWrapper ${retroarch}/bin/retroarch $out/bin/retroarch \
      --suffix-each LD_LIBRARY_PATH ':' "$cores" \
      --add-flags "-L $out/lib/" \
      ${wrapperArgs}
  '' + lib.optionalString stdenv.isDarwin ''
    # wrapProgram can't operate on symlinks
    rm $out/Applications/RetroArch.app/Contents/MacOS/retroarch
    makeWrapper ${retroarch}/bin/retroarch $out/Applications/RetroArch.app/Contents/MacOS/retroarch \
      ${wrapperArgs}
  '';

  cores = map (x: x + x.libretroCore) cores;
  preferLocalBuild = true;

  meta = with retroarch.meta; {
    inherit changelog description homepage license maintainers platforms;
    longDescription = ''
      RetroArch is the reference frontend for the libretro API.

      The following cores are included:
      ${lib.concatStringsSep "\n" (map (x: "  - ${x.name}") cores)}
    ''
    + lib.optionalString (cores != [ ]) ''
      The following cores are included: ${lib.concatStringsSep ", " (map (x: x.core) cores)}
    '';
    # FIXME: exit with error on macOS:
    # No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting
    broken = stdenv.isDarwin;
    mainProgram = "retroarch";
  };
}