retronix/pkgs/wrap-retroarch.nix
2024-01-17 13:33:06 +01:00

60 lines
1.5 KiB
Nix

{ 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 (lib.unique (map (c: c.libretroCore) cores)) == 1)
"Libretro cores are not under the same paths: ${builtins.toString (lib.unique (builtins.map (c: c.libretroCore) cores))}";
(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 = ''
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";
};
}