libretro.melondsds: custom updateScript

This commit is contained in:
Igor Melo
2026-06-10 00:47:23 -03:00
parent 82dd7b41b6
commit 9be73a459c
@@ -1,16 +1,24 @@
{
lib,
applyPatches,
coreutils,
fetchFromGitHub,
glm,
libslirp,
fmt_11,
span-lite,
glm,
gnugrep,
gnused,
howard-hinnant-date,
jq,
libGL,
libGLU,
cmake,
libslirp,
mkLibretroCore,
nix,
nix-prefetch-git,
cmake,
span-lite,
unstableGitUpdater,
writeShellApplication,
}:
let
# https://github.com/JesseTG/melonds-ds/blob/33c48260402865ef77667487528efd5ca7ce1233/cmake/FetchDependencies.cmake#L44
@@ -99,6 +107,79 @@ mkLibretroCore rec {
postBuild = "cd src/libretro";
passthru.updateScript = [
(lib.getExe (writeShellApplication {
name = "update-libretro-melondsds";
runtimeInputs = [
coreutils
gnugrep
gnused
jq
nix
nix-prefetch-git
];
text = ''
${lib.escapeShellArgs (unstableGitUpdater {
hardcodeZeroVersion = true;
})}
src=$(nix-build --no-out-link -A "$UPDATE_NIX_ATTR_PATH.src")
core_file="pkgs/applications/emulators/libretro/cores/melondsds.nix"
# find lines in the format:
# fetch_dependency(name url rev)
# and extracts name, url and rev
grep "^fetch_dependency" "''${src}/cmake/FetchDependencies.cmake" |
sed 's/"//g' |
sed 's/fetch_dependency(\(.*\))/\1/' |
while read -r name url rev
do
echo >&2
# example: if there is fetch_dependency(melonDS ...) and no melonDS-src
if ! fetch_block=$(grep -A10 "''${name}-src =" "$core_file")
then
# if the dependency comes from nix, we just skip it
if grep -q "FETCHCONTENT_SOURCE_DIR_''${name^^}" "$core_file"
then
echo "> skipped: ''${name} is provided by nixpkgs" >&2
continue
fi
# otherwise, its a new dependency not specified on the config, and the updater can't continue
echo "> ERROR: dependency missing: ''${name}" >&2
exit 1
fi
echo "> ''${name}: ''${url} (''${rev})" >&2
prefetch=$(nix-prefetch-git --url "''${url}" --rev "''${rev}" --quiet)
rev=$(echo "$prefetch" | jq -r ".rev")
hash=$(echo "$prefetch" | jq -r ".hash")
old_rev=$(echo "$fetch_block" | grep -m1 "rev =" | sed 's/\s*rev = "\(.*\)".*/\1/')
old_hash=$(echo "$fetch_block" | grep -m1 "hash =" | sed 's/\s*hash = "\(.*\)".*/\1/')
if [[ "$old_hash" == "$hash" ]]
then
echo "> skipped: same hash" >&2
continue
fi
echo "rev - old: $old_rev" >&2
echo "rev - new: $rev" >&2
echo "hash - old: $old_hash" >&2
echo "hash - new: $hash" >&2
# finally replace old revision and old hash by the new one
sed -i "s|$old_hash|$hash|" "$core_file"
sed -i "s/$old_rev/$rev/" "$core_file"
done
'';
}))
];
meta = {
description = "A remake of the libretro MelonDS core";
homepage = "https://github.com/JesseTG/melonds-ds";