nixpkgs-suyu/pkgs/games/nethack/default.nix

97 lines
2.4 KiB
Nix
Raw Normal View History

{ stdenv, lib, fetchurl, writeScript, ncurses, gzip, flex, bison }:
2015-06-29 13:19:12 +02:00
let
platform =
if lib.elem stdenv.system lib.platforms.unix then "unix"
else abort "Unknown platform for NetHack";
unixHint =
if stdenv.isLinux then "linux"
2016-02-29 04:04:23 +01:00
else if stdenv.isDarwin then "macosx10.10"
# We probably want something different for Darwin
else "unix";
2015-12-08 16:10:53 +01:00
userDir = "~/.config/nethack";
in stdenv.mkDerivation {
name = "nethack-3.6.0";
2015-06-29 13:19:12 +02:00
src = fetchurl {
url = "mirror://sourceforge/nethack/nethack-360-src.tgz";
sha256 = "12mi5kgqw3q029y57pkg3gnp930p7yvlqi118xxdif2qhj6nkphs";
};
2015-06-29 13:19:12 +02:00
buildInputs = [ ncurses ];
nativeBuildInputs = [ flex bison ];
makeFlags = [ "PREFIX=$(out)" ];
2016-02-29 04:04:23 +01:00
patchPhase = ''
sed -e '/^ *cd /d' -i sys/unix/nethack.sh
sed \
-e 's/^YACC *=.*/YACC = bison -y/' \
-e 's/^LEX *=.*/LEX = flex/' \
-i sys/unix/Makefile.utl
sed \
-e 's,/bin/gzip,${gzip}/bin/gzip,g' \
-e 's,^WINTTYLIB=.*,WINTTYLIB=-lncurses,' \
-i sys/unix/hints/linux
sed \
-e 's,^CC=.*$,CC=cc,' \
-e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \
-e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \
-i sys/unix/hints/macosx10.10
sed -e '/define CHDIR/d' -i include/config.h
'';
configurePhase = ''
cd sys/${platform}
${lib.optionalString (platform == "unix") ''
sh setup.sh hints/${unixHint}
''}
cd ../..
2015-06-29 13:19:12 +02:00
'';
postInstall = ''
mkdir -p $out/games/lib/nethackuserdir
for i in xlogfile logfile perm record save; do
mv $out/games/lib/nethackdir/$i $out/games/lib/nethackuserdir
2015-06-29 13:19:12 +02:00
done
mkdir -p $out/bin
2015-06-29 13:19:12 +02:00
cat <<EOF >$out/bin/nethack
2015-12-08 16:10:53 +01:00
#! ${stdenv.shell} -e
2015-06-29 13:19:12 +02:00
2015-12-08 16:10:53 +01:00
if [ ! -d ${userDir} ]; then
mkdir -p ${userDir}
cp -r $out/games/lib/nethackuserdir/* ${userDir}
chmod -R +w ${userDir}
fi
2015-06-29 13:19:12 +02:00
2016-02-29 04:04:23 +01:00
RUNDIR=\$(mktemp -d)
2015-06-29 13:19:12 +02:00
2015-12-08 16:10:53 +01:00
cleanup() {
rm -rf \$RUNDIR
}
trap cleanup EXIT
cd \$RUNDIR
for i in ${userDir}/*; do
ln -s \$i \$(basename \$i)
done
for i in $out/games/lib/nethackdir/*; do
ln -s \$i \$(basename \$i)
done
$out/games/nethack
2015-06-29 13:19:12 +02:00
EOF
chmod +x $out/bin/nethack
'';
meta = with stdenv.lib; {
description = "Rogue-like game";
homepage = "http://nethack.org/";
license = "nethack";
platforms = platforms.unix;
maintainers = with maintainers; [ abbradar ];
};
}