From 801cc447659ee28e15b521f08e84df9c3d5f1bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Wed, 19 Jul 2023 13:11:14 +0200 Subject: [PATCH 1/3] 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). --- .../emulators/retroarch/wrapper.nix | 18 +++++++++++++++--- pkgs/top-level/all-packages.nix | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/emulators/retroarch/wrapper.nix b/pkgs/applications/emulators/retroarch/wrapper.nix index afef0bef8a48..4698bbe5bbed 100644 --- a/pkgs/applications/emulators/retroarch/wrapper.nix +++ b/pkgs/applications/emulators/retroarch/wrapper.nix @@ -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}"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cf4fcc344741..786c227cd7de 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { From 35c3c81655802b4d039754e0b2ba0248583e11b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Wed, 19 Jul 2023 13:29:45 +0200 Subject: [PATCH 2/3] retroarch-joypad-autoconfig: init at 1.15.0 https://github.com/libretro/retroarch-joypad-autoconfig (In preparation for making joypads work out-of-the-box in RetroArch.) --- .../retroarch/retroarch-joypad-autoconfig.nix | 28 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 pkgs/applications/emulators/retroarch/retroarch-joypad-autoconfig.nix diff --git a/pkgs/applications/emulators/retroarch/retroarch-joypad-autoconfig.nix b/pkgs/applications/emulators/retroarch/retroarch-joypad-autoconfig.nix new file mode 100644 index 000000000000..92ba7f20c8b3 --- /dev/null +++ b/pkgs/applications/emulators/retroarch/retroarch-joypad-autoconfig.nix @@ -0,0 +1,28 @@ +{ lib +, stdenvNoCC +, fetchFromGitHub +}: + +stdenvNoCC.mkDerivation rec { + pname = "retroarch-joypad-autoconfig"; + version = "1.15.0"; + + src = fetchFromGitHub { + owner = "libretro"; + repo = "retroarch-joypad-autoconfig"; + rev = "v${version}"; + hash = "sha256-/F2Y08uDA/pIIeLiLfOQfGVjX2pkuOqPourlx2RbZ28="; + }; + + makeFlags = [ + "PREFIX=$(out)" + ]; + + meta = with lib; { + description = "Joypad autoconfig files"; + homepage = "https://www.libretro.com/"; + license = licenses.mit; + maintainers = with maintainers; teams.libretro.members ++ [ ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 786c227cd7de..70beb3e102f3 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2655,6 +2655,8 @@ with pkgs; retroarch-assets = callPackage ../applications/emulators/retroarch/retroarch-assets.nix { }; + retroarch-joypad-autoconfig = callPackage ../applications/emulators/retroarch/retroarch-joypad-autoconfig.nix { }; + libretranslate = with python3.pkgs; toPythonApplication libretranslate; libretro = recurseIntoAttrs From 9d793505b9e2b5d58f50e60ebfa74d7bd0665cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Wed, 19 Jul 2023 14:01:25 +0200 Subject: [PATCH 3/3] retroarch: auto-detect joypads Set the 'joypad_autoconfig_dir' setting to where autoconfig files are, instead of using the built-in default of ~/.config/retroarch/autoconfig, which is empty. Tested with my PS5 DualSense controller, which now works. --- pkgs/top-level/all-packages.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 70beb3e102f3..74188daa63d8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2651,6 +2651,9 @@ with pkgs; withAssets = true; withCoreInfo = true; }; + settings = { + joypad_autoconfig_dir = "${retroarch-joypad-autoconfig}/share/libretro/autoconfig"; + }; }; retroarch-assets = callPackage ../applications/emulators/retroarch/retroarch-assets.nix { };