add ability to pass settings to retroarch

This commit is contained in:
sinavir 2024-01-11 02:00:21 +01:00
parent 95f06dbf68
commit 75e663ab74
9 changed files with 88 additions and 11 deletions

View file

@ -35,4 +35,7 @@ final: prev: {
'';
roms = final.callPackage ./roms {};
wrapRetroarch' = { retroarch, cores ? [ ], settings ? { } }:
final.callPackage ./wrap-retroarch.nix { inherit retroarch cores settings; };
}

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}:
{mkRetroarchRom, settings ? {}}:
mkRetroarchRom {
name = "atetris";
src = ./bin/atetris;
inherit settings;
emulator = "";
filename = "atetris.zip";

View file

@ -1,15 +1,17 @@
{ mkRom , retroarchFull }:
{ mkRom , lib, symlinkJoin, libretro, stdenv, retroarchBare, retroarchFull, wrapRetroarch' }:
{ name
, src
, emulator
, filename
, settings ? {}
, settings
, meta
}:
let
retroarch = retroarchFull.override (prev: {
settings = prev.settings // settings;
});
retroarch = wrapRetroarch' {
retroarch = retroarchBare;
cores = retroarchFull.cores;
inherit settings;
};
in
mkRom ({
runtimeInputs = [ retroarch ];

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}:
{mkRetroarchRom, settings ? {}}:
mkRetroarchRom {
name = "dkong";
src = ./bin/dkong;
inherit settings;
emulator = "fbneo";
filename = "dkong.zip";

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}:
{mkRetroarchRom, settings ? {}}:
mkRetroarchRom {
name = "mario";
src = ./bin/mario;
inherit settings;
emulator = "fbneo";
filename = "mario.zip";

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}:
{mkRetroarchRom, settings ? {}}:
mkRetroarchRom {
name = "neopong";
src = ./bin/neopong;
inherit settings;
emulator = "fbneo";
filename = "neopong.zip";

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}:
{mkRetroarchRom, settings ? {}}:
mkRetroarchRom {
name = "pacman";
src = ./bin/pacman;
inherit settings;
emulator = "fbneo";
filename = "pacman.zip";

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}:
{mkRetroarchRom, settings ? {}}:
mkRetroarchRom {
name = "spacedx";
src = ./bin/spacedx;
inherit settings;
emulator = "fbneo";
filename = "spacedx.zip";

60
pkgs/wrap-retroarch.nix Normal file
View file

@ -0,0 +1,60 @@
{ lib
, stdenv
, makeWrapper
, symlinkJoin
, runCommand
, retroarch
, cores ? [ ]
, settings ? { }
}:
let
settings' = { libretro_directory = coresPath; } // settings;
settingsPath = runCommand "declarative-retroarch.cfg"
{
value = lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "${n} = \"${v}\"") settings);
passAsFile = [ "value" ];
}
''
cp "$valuePath" "$out"
'';
coresPath = let
path = assert
lib.assertMsg (builtins.length (map (c: c.libretroCore) cores) == 1)
"Libretro cores are not under the same paths";
(builtins.head cores).libretroCore;
in
symlinkJoin {
name = "retroarch-cores";
paths = cores;
} + path;
wrapperArgs = lib.strings.escapeShellArgs [ "--add-flags" "--config=${settingsPath}" ];
in
symlinkJoin {
name = "retroarch-with-cores-${lib.getVersion retroarch}";
paths = [ retroarch ];
nativeBuildInputs = [ makeWrapper ];
passthru = {
inherit cores;
unwrapped = retroarch;
};
postBuild = ''
# wrap binary to load cores from the proper location(s)
wrapProgram $out/bin/retroarch ${wrapperArgs}
'';
meta = with retroarch.meta; {
inherit changelog description homepage license maintainers platforms;
longDescription = ''
RetroArch is the reference frontend for the libretro API.
''
+ lib.optionalString (cores != [ ]) ''
The following cores are included: ${lib.concatStringsSep ", " (map (c: c.core) cores)}
'';
mainProgram = "retroarch";
};
}