1{ stdenv, fetchurl, writeScript, ncurses, gzip, flex, bison }:
2
3stdenv.mkDerivation rec {
4 name = "nethack-3.4.3";
5
6 src = fetchurl {
7 url = "mirror://sourceforge/nethack/nethack-343-src.tgz";
8 sha256 = "1r3ghqj82j0bar62z3b0lx9hhx33pj7p1ppxr2hg8bgfm79c6fdv";
9 };
10
11 buildInputs = [ ncurses ];
12
13 nativeBuildInputs = [ flex bison ];
14
15 preBuild = ''
16 ( cd sys/unix ; sh setup.sh )
17
18 sed -e '/define COMPRESS/d' -i include/config.h
19 sed -e '1i\#define COMPRESS "${gzip}/bin/gzip"' -i include/config.h
20 sed -e '1i\#define COMPRESS_EXTENSION ".gz"' -i include/config.h
21 sed -e '/define CHDIR/d' -i include/config.h
22
23 sed -e '/extern char [*]tparm/d' -i win/tty/*.c
24
25 sed -e 's/-ltermlib/-lncurses/' -i src/Makefile
26 sed -e 's/^YACC *=.*/YACC = bison -y/' -i util/Makefile
27 sed -e 's/^LEX *=.*/LEX = flex/' -i util/Makefile
28
29 sed -re 's@^(CH...).*@\1 = true@' -i Makefile
30
31 sed -e '/^ *cd /d' -i sys/unix/nethack.sh
32 '';
33
34 postInstall = ''
35 for i in logfile perm record save; do
36 rm -rf $out/games/lib/nethackdir/$i
37 done
38
39 mkdir -p $out/bin
40 cat <<EOF >$out/bin/nethack
41 #! ${stdenv.shell} -e
42 if [ ! -d ~/.nethack ]; then
43 mkdir -p ~/.nethack/save
44 for i in logfile perm record; do
45 [ ! -e ~/.nethack/\$i ] && touch ~/.nethack/\$i
46 done
47 fi
48
49 cd ~/.nethack
50
51 cleanup() {
52 for i in $out/games/lib/nethackdir/*; do
53 rm -rf \$(basename \$i)
54 done
55 }
56 trap cleanup EXIT
57
58 for i in $out/games/lib/nethackdir/*; do
59 ln -s \$i \$(basename \$i)
60 done
61 $out/games/nethack
62 EOF
63 chmod +x $out/bin/nethack
64 '';
65
66 makeFlags = [ "PREFIX=$(out)" ];
67
68 meta = with stdenv.lib; {
69 description = "Rogue-like game";
70 homepage = "http://nethack.org/";
71 license = "nethack";
72 platforms = platforms.unix;
73 maintainers = with maintainers; [ abbradar ];
74 };
75}