keen4: modernize

It all starts with fixing the broken download URL and then simplifies
from there. The file is short and old enough to basically just rewrite
it once.
This commit is contained in:
Wolfgang Walther
2025-03-16 19:23:30 +01:00
parent 367c15cfe8
commit 117b2045e8
+28 -41
View File
@@ -1,56 +1,43 @@
{
lib,
stdenv,
fetchurl,
dosbox,
unzip,
fetchzip,
lib,
writeShellApplication,
}:
stdenv.mkDerivation {
let
zip = fetchzip {
name = "keen4.zip";
url = "https://archive.org/download/msdos_Commander_Keen_4_-_Secret_of_the_Oracle_1991/Commander_Keen_4_-_Secret_of_the_Oracle_1991.zip";
hash = "sha256-vVfBQArNH1JPUxM5suMe8NK54a+NAMnDhLKxVUOzUgA=";
};
in
writeShellApplication {
name = "keen4";
src = fetchurl {
url = "http://tarballs.nixos.org/keen4.zip";
sha256 = "12rnc9ksl7v6l8wsxvr26ylkafzq80dbsa7yafzw9pqc8pafkhx1";
};
runtimeInputs = [ dosbox ];
nativeBuildInputs = [ unzip ];
# Game wants to write in the current directory, but of course we can't
# let it write in the Nix store. So create symlinks to the game files
# in ~/.keen4 and execute game from there.
text = ''
mkdir -p "''${HOME:-.}/.keen4"
cd "''${HOME:-.}/.keen4"
# avoid linking CONFIG.CK4, which must be writable
ln -sft . ${zip}/{AUDIO.CK4,EGAGRAPH.CK4,GAMEMAPS.CK4,KEEN4E.EXE}
trap 'find . -type l -delete' EXIT
installPhase = ''
mkdir -p $out/share/keen4
mv * $out/share/keen4
mkdir -p $out/bin
cat > $out/bin/keen4 <<EOF
#! $SHELL -e
if test -z "\$HOME"; then
echo "HOME directory not set"
exit 1
fi
# Game wants to write in the current directory, but of course we can't
# let it write in the Nix store. So create symlinks to the game files
# in ~/.keen4 and execute game from there.
mkdir -p \$HOME/.keen4
cd \$HOME/.keen4
ln -sf $out/share/keen4/* .
${dosbox}/bin/dosbox ./KEEN4E.EXE -fullscreen -exit || true
# Cleanup the symlinks.
for i in *; do
if test -L "\$i"; then
rm "\$i"
fi
done
EOF
chmod +x $out/bin/keen4
dosbox ./KEEN4E.EXE -fullscreen -exit
'';
meta = {
description = "Commander Keen Episode 4: Secret of the Oracle";
license = lib.licenses.unfree;
homepage = "https://web.archive.org/web/20141013080934/http://www.3drealms.com/keen4/index.html";
downloadPage = "https://archive.org/details/msdos_Commander_Keen_4_-_Secret_of_the_Oracle_1991";
license = lib.licenses.unfreeRedistributable;
platforms = dosbox.meta.platforms;
sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; # emulated by dosbox, so "bytecode" in a way
maintainers = with lib.maintainers; [ wolfgangwalther ];
mainProgram = "keen4";
};
}