retronix/pkgs/roms/build/mkRom.nix

55 lines
1 KiB
Nix
Raw Permalink Normal View History

2024-01-06 22:42:36 +01:00
{ runCommand, runtimeShell, stdenv, shellcheck-minimal, lib, lndir }:
{ name
, src
, runtimeInputs ? [ ]
, command
, meta ? {}
}:
runCommand name {
inherit meta src;
allowSubstitutes = true;
preferLocalBuild = false;
launchPath = "launch.sh";
script = ''
#!${runtimeShell}
set -o errexit
set -o nounset
set -o pipefail
'' + lib.optionalString (runtimeInputs != [ ]) ''
export PATH="${lib.makeBinPath runtimeInputs}:$PATH"
'' + ''
${command}
'';
passAsFile = [ "script" ];
checkPhase = ''
runHook preCheck
${stdenv.shellDryRun} "$target"
${lib.getExe shellcheck-minimal} "$target"
runHook postCheck
'';
} ''
target=$out/bin/${lib.escapeShellArg name}
rom_dir=$out/usr/share
mkdir -p "$(dirname "$target")"
mkdir -p "$rom_dir"
# symlink rom_dir
${lndir}/bin/lndir $src $rom_dir
mv "$scriptPath" "$target"
chmod +x "$target"
# symlink the executable to help emulation station calls
ln -s $target $out/$launchPath
eval "$checkPhase"
''