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 {}; 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 { mkRetroarchRom {
name = "atetris"; name = "atetris";
src = ./bin/atetris; src = ./bin/atetris;
inherit settings;
emulator = ""; emulator = "";
filename = "atetris.zip"; filename = "atetris.zip";

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,10 @@
{mkRetroarchRom}: {mkRetroarchRom, settings ? {}}:
mkRetroarchRom { mkRetroarchRom {
name = "spacedx"; name = "spacedx";
src = ./bin/spacedx; src = ./bin/spacedx;
inherit settings;
emulator = "fbneo"; emulator = "fbneo";
filename = "spacedx.zip"; 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";
};
}