This commit is contained in:
mjallen18
2025-02-20 11:32:05 -06:00
parent 43ecae9920
commit 948e4b199a
22 changed files with 218 additions and 276 deletions

View File

@@ -6,48 +6,129 @@ with lib;
let
cfg = config.programs.steam-rom-manager;
# Function to find the main binary in a package
findMainBinary = pkg: name:
let
# First try to find a binary that matches the package name
pkgName = pkg.pname or (builtins.parseDrvName pkg.name).name;
# binPath = "${pkg}/bin/${pkgName}";
# Common binary name variations
commonVariants = [
pkgName # e.g., "citra"
"${pkgName}-qt" # e.g., "citra-qt"
"${pkgName}-gtk" # e.g., "citra-gtk"
"${pkgName}-emu" # e.g., "dolphin-emu"
];
# Check if any of the common variants exist
existingVariant = findFirst
(variant: builtins.pathExists "${pkg}/bin/${variant}")
null
commonVariants;
in
# Use the override if provided, otherwise try to find the binary
if name != ""
then name
else if existingVariant != null
then existingVariant
else pkgName; # Fallback to package name
# Common emulator configurations
commonEmulatorConfigs = {
ryujinx = {
romFolder = "switch";
binaryName = "Ryujinx";
fileTypes = [ ".nca" ".NCA" ".nro" ".NRO" ".nso" ".NSO" ".nsp" ".NSP" ".xci" ".XCI" ];
};
yuzu = {
romFolder = "switch";
binaryName = "yuzu";
fileTypes = [ ".nsp" ".NSP" ".xci" ".XCI" ];
};
pcsx2 = {
romFolder = "ps2";
binaryName = "pcsx2-qt";
fileTypes = [ ".iso" ".ISO" ".bin" ".BIN" ".chd" ".CHD" ];
};
rpcs3 = {
romFolder = "ps3";
binaryName = "rpcs3";
fileTypes = [ ".iso" ".ISO" ".bin" ".BIN" ".pkg" ".PKG" ];
};
dolphin-emu = {
romFolder = "gc";
binaryName = "dolphin-emu";
fileTypes = [ ".iso" ".ISO" ".gcm" ".GCM" ".ciso" ".CISO" ];
};
duckstation = {
romFolder = "psx";
binaryName = "duckstation-qt";
fileTypes = [ ".iso" ".ISO" ".bin" ".BIN" ".chd" ".CHD" ".pbp" ".PBP" ];
};
melonDS = {
romFolder = "nds";
binaryName = "melonDS";
fileTypes = [ ".nds" ".NDS" ];
};
cemu = {
romFolder = "wiiu";
binaryName = "cemu";
fileTypes = [ ".wud" ".WUD" ".wux" ".WUX" ".rpx" ".RPX" ];
};
# Added default configurations
xemu = {
romFolder = "xbox";
fileTypes = [ ".iso" ".ISO" ];
};
xenia = {
romFolder = "xbox360";
fileTypes = [ ".iso" ".ISO" ".xex" ".XEX" ];
};
ppsspp = {
romFolder = "psp";
fileTypes = [ ".iso" ".ISO" ".cso" ".CSO" ".pbp" ".PBP" ];
};
vita3k = {
romFolder = "psvita";
fileTypes = [ ".vpk" ".VPK" ];
};
mame = {
romFolder = "arcade";
fileTypes = [ ".zip" ".ZIP" ".7z" ".7Z" ];
};
dosbox = {
romFolder = "dos";
fileTypes = [ ".exe" ".EXE" ".bat" ".BAT" ".com" ".COM" ];
};
pcem = {
romFolder = "pcem";
fileTypes = [ ".img" ".IMG" ".ima" ".IMA" ];
};
snes9x = {
romFolder = "snes";
fileTypes = [ ".smc" ".SMC" ".sfc" ".SFC" ".fig" ".FIG" ];
};
mgba = {
romFolder = "gba";
fileTypes = [ ".gba" ".GBA" ];
};
mupen64plus = {
romFolder = "n64";
fileTypes = [ ".n64" ".N64" ".v64" ".V64" ".z64" ".Z64" ];
};
retroarch = {
romFolder = "retroarch";
fileTypes = [ ".zip" ".ZIP" ".7z" ".7Z" ".iso" ".ISO" ".bin" ".BIN" ".chd" ".CHD" ];
};
dolphin-triforce = {
romFolder = "triforce";
fileTypes = [ ".iso" ".ISO" ".gcm" ".GCM" ];
};
flycast = {
romFolder = "dreamcast";
fileTypes = [ ".gdi" ".GDI" ".cdi" ".CDI" ".chd" ".CHD" ];
};
citra = {
romFolder = "3ds";
fileTypes = [ ".3ds" ".3DS" ".cia" ".CIA" ".cxi" ".CXI" ];
};
demul = {
romFolder = "demul";
fileTypes = [ ".gdi" ".GDI" ".cdi" ".CDI" ".chd" ".CHD" ];
};
};
getFileTypes = name: emu:
@@ -57,6 +138,9 @@ let
mkParserConfig = name: emu:
let
# Get the binary name dynamically if not explicitly set
binaryName = findMainBinary emu.package emu.binaryName;
# We create an ordered list of key-value pairs that will maintain the exact order
# in the generated JSON output. Each field is documented for clarity.
orderedConfig = [
@@ -96,7 +180,7 @@ let
# Executable details
{ name = "executable"; value = {
path = "${emu.package}/bin/${if emu.binaryName != "" then emu.binaryName else commonEmulatorConfigs.${name}.binaryName}";
path = "${emu.package}/bin/${binaryName}";
shortcutPassthrough = false;
appendArgsToExecutable = true;
}; }
@@ -250,11 +334,6 @@ in {
type = types.package;
description = "Emulator package";
};
binaryName = mkOption {
type = types.str;
default = "";
description = "Name of the emulator binary (defaults to common configuration)";
};
romFolder = mkOption {
type = types.str;
default = "";