2018-06-29 14:21:56 +02:00
|
|
|
{ stdenv, lib, fetchurl, writeScript, coreutils, ncurses, gzip, flex, bison, less
|
|
|
|
, x11Mode ? false, libXaw, libXext, mkfontdir
|
|
|
|
}:
|
2015-06-29 13:19:12 +02:00
|
|
|
|
2015-12-08 15:45:44 +01:00
|
|
|
let
|
|
|
|
platform =
|
2018-03-10 00:40:51 +01:00
|
|
|
if stdenv.hostPlatform.isUnix then "unix"
|
2017-12-06 00:06:43 +01:00
|
|
|
else throw "Unknown platform for NetHack: ${stdenv.system}";
|
2015-12-08 15:45:44 +01:00
|
|
|
unixHint =
|
2018-06-29 14:21:56 +02:00
|
|
|
if x11Mode then "linux-x11"
|
|
|
|
else if stdenv.hostPlatform.isLinux then "linux"
|
2018-03-10 00:40:51 +01:00
|
|
|
else if stdenv.hostPlatform.isDarwin then "macosx10.10"
|
2015-12-08 15:45:44 +01:00
|
|
|
# We probably want something different for Darwin
|
|
|
|
else "unix";
|
2015-12-08 16:10:53 +01:00
|
|
|
userDir = "~/.config/nethack";
|
2017-04-06 15:27:36 +02:00
|
|
|
binPath = lib.makeBinPath [ coreutils less ];
|
2015-12-08 15:45:44 +01:00
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
2018-06-29 14:21:56 +02:00
|
|
|
name = "nethack${lib.optionalString x11Mode "-x11"}-3.6.1";
|
2015-06-29 13:19:12 +02:00
|
|
|
|
2009-05-12 06:27:10 +02:00
|
|
|
src = fetchurl {
|
2018-06-28 20:43:35 +02:00
|
|
|
url = "https://nethack.org/download/3.6.1/nethack-361-src.tgz";
|
2018-06-10 04:33:13 +02:00
|
|
|
sha256 = "1dha0ijvxhx7c9hr0452h93x81iiqsll8bc9msdnp7xdqcfbz32b";
|
2009-05-12 06:27:10 +02:00
|
|
|
};
|
|
|
|
|
2018-06-29 14:21:56 +02:00
|
|
|
buildInputs = [ ncurses ] ++ lib.optionals x11Mode [ libXaw libXext ];
|
2015-06-29 13:19:12 +02:00
|
|
|
|
2018-06-29 14:21:56 +02:00
|
|
|
nativeBuildInputs = [ flex bison ] ++ lib.optionals x11Mode [ mkfontdir ];
|
2009-05-12 06:27:10 +02:00
|
|
|
|
2015-12-08 15:45:44 +01:00
|
|
|
makeFlags = [ "PREFIX=$(out)" ];
|
2009-05-12 06:27:10 +02:00
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2015-12-08 15:45:44 +01:00
|
|
|
configurePhase = ''
|
|
|
|
cd sys/${platform}
|
|
|
|
${lib.optionalString (platform == "unix") ''
|
|
|
|
sh setup.sh hints/${unixHint}
|
|
|
|
''}
|
|
|
|
cd ../..
|
2015-06-29 13:19:12 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
2015-12-08 15:45:44 +01:00
|
|
|
mkdir -p $out/games/lib/nethackuserdir
|
2016-06-03 08:46:34 +02:00
|
|
|
for i in xlogfile logfile perm record save; do
|
2015-12-08 15:45:44 +01:00
|
|
|
mv $out/games/lib/nethackdir/$i $out/games/lib/nethackuserdir
|
2015-06-29 13:19:12 +02:00
|
|
|
done
|
|
|
|
|
2012-01-18 21:16:00 +01:00
|
|
|
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
|
2017-04-06 15:27:36 +02:00
|
|
|
PATH=${binPath}:\$PATH
|
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
|
2018-06-29 14:21:56 +02:00
|
|
|
${lib.optionalString x11Mode "mv $out/bin/nethack $out/bin/nethack-x11"}
|
2015-06-29 13:19:12 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "Rogue-like game";
|
2017-08-01 22:03:30 +02:00
|
|
|
homepage = http://nethack.org/;
|
2015-06-29 13:19:12 +02:00
|
|
|
license = "nethack";
|
2018-06-29 14:21:56 +02:00
|
|
|
platforms = if x11Mode then platforms.linux else platforms.unix;
|
2015-06-29 13:19:12 +02:00
|
|
|
maintainers = with maintainers; [ abbradar ];
|
2009-05-12 06:27:10 +02:00
|
|
|
};
|
|
|
|
}
|