Commit 801cc447 authored by Bjørn Forsman's avatar Bjørn Forsman
Browse files

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).
parent 7120535c
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -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}";
+2 −2
Original line number Diff line number Diff line
@@ -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 {