2022-10-30 15:09:59 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, makeWrapper
|
|
|
|
, retroarch
|
|
|
|
, symlinkJoin
|
2023-08-04 22:07:22 +00:00
|
|
|
, runCommand
|
2022-10-30 15:09:59 +00:00
|
|
|
, cores ? [ ]
|
2023-08-04 22:07:22 +00:00
|
|
|
, settings ? { }
|
2022-10-30 15:09:59 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-08-04 22:07:22 +00:00
|
|
|
settingsPath = runCommand "declarative-retroarch.cfg"
|
|
|
|
{
|
|
|
|
value = lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "${n} = \"${v}\"") settings);
|
|
|
|
passAsFile = [ "value" ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
cp "$valuePath" "$out"
|
|
|
|
'';
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
# All cores should be located in the same path after symlinkJoin,
|
|
|
|
# but let's be safe here
|
|
|
|
coresPath = lib.lists.unique (map (c: c.libretroCore) cores);
|
2023-08-04 22:07:22 +00:00
|
|
|
wrapperArgs = lib.strings.escapeShellArgs (
|
|
|
|
(lib.lists.flatten (map (p: [ "--add-flags" "-L ${placeholder "out" + p}" ]) coresPath))
|
|
|
|
++ [ "--add-flags" "--appendconfig=${settingsPath}" ]
|
|
|
|
);
|
2022-10-30 15:09:59 +00:00
|
|
|
in
|
|
|
|
symlinkJoin {
|
|
|
|
name = "retroarch-with-cores-${lib.getVersion retroarch}";
|
|
|
|
|
|
|
|
paths = [ retroarch ] ++ cores;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
passthru = {
|
|
|
|
inherit cores;
|
|
|
|
unwrapped = retroarch;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
postBuild = ''
|
|
|
|
# remove core specific binaries
|
|
|
|
find $out/bin -name 'retroarch-*' -type l -delete
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
# wrap binary to load cores from the proper location(s)
|
|
|
|
wrapProgram $out/bin/retroarch ${wrapperArgs}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with retroarch.meta; {
|
2022-02-21 08:47:16 +00:00
|
|
|
inherit changelog description homepage license maintainers platforms;
|
2022-04-15 01:41:22 +00:00
|
|
|
longDescription = ''
|
|
|
|
RetroArch is the reference frontend for the libretro API.
|
2022-10-30 15:09:59 +00:00
|
|
|
''
|
|
|
|
+ lib.optionalString (cores != [ ]) ''
|
|
|
|
The following cores are included: ${lib.concatStringsSep ", " (map (c: c.core) cores)}
|
2022-04-15 01:41:22 +00:00
|
|
|
'';
|
2022-10-30 15:09:59 +00:00
|
|
|
mainProgram = "retroarch";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|