retroarch: add support for declarative settings

Add a new optional 'settings' attrset to the wrapper derivation, which
gets serialized to a file and passed to RetroArch as --appendconfig= at
runtime. This allows overriding settings from
~/.config/retroarch/retroarch.cfg (which initially gets created as a
dump of all internal retroarch settings -- stateful and messy).
This commit is contained in:
Bjørn Forsman 2023-07-19 13:11:14 +02:00
parent 7120535c32
commit 801cc44765
2 changed files with 17 additions and 5 deletions

View file

@ -3,16 +3,28 @@
, makeWrapper
, retroarch
, symlinkJoin
, runCommand
, cores ? [ ]
, settings ? { }
}:
let
settingsPath = runCommand "declarative-retroarch.cfg"
{
value = lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "${n} = \"${v}\"") settings);
passAsFile = [ "value" ];
}
''
cp "$valuePath" "$out"
'';
# 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);
wrapperArgs = lib.strings.escapeShellArgs
(lib.lists.flatten
(map (p: [ "--add-flags" "-L ${placeholder "out" + p}" ]) coresPath));
wrapperArgs = lib.strings.escapeShellArgs (
(lib.lists.flatten (map (p: [ "--add-flags" "-L ${placeholder "out" + p}" ]) coresPath))
++ [ "--add-flags" "--appendconfig=${settingsPath}" ]
);
in
symlinkJoin {
name = "retroarch-with-cores-${lib.getVersion retroarch}";

View file

@ -2642,9 +2642,9 @@ with pkgs;
(builtins.attrValues libretro);
};
wrapRetroArch = { retroarch }:
wrapRetroArch = { retroarch, settings ? {} }:
callPackage ../applications/emulators/retroarch/wrapper.nix
{ inherit retroarch; };
{ inherit retroarch settings; };
retroarch = wrapRetroArch {
retroarch = retroarchBare.override {