retroarch: refactor wrapper to use symlinkJoin

This commit is contained in:
Thiago Kenji Okada
2022-10-28 16:33:26 +01:00
parent 64ae43e9e5
commit cb5179db83
2 changed files with 36 additions and 27 deletions
@@ -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;
};
}
@@ -1,41 +1,51 @@
{ stdenv, lib, makeWrapper, retroarch, cores ? [ ] }:
{ lib
, stdenv
, makeWrapper
, retroarch
, symlinkJoin
, cores ? [ ]
}:
stdenv.mkDerivation {
pname = "retroarch";
version = lib.getVersion retroarch;
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";
};
}