1 { stdenv, lib, fetchurl, coreutils, ncurses, gzip, flex, bison
4 , x11Mode ? false, qtMode ? false, libXaw, libXext, libXpm, bdftopcf, mkfontdir, pkg-config, qt5
5 , copyDesktopItems, makeDesktopItem
10 if stdenv.hostPlatform.isUnix then "unix"
11 else throw "Unknown platform for NetHack: ${stdenv.hostPlatform.system}";
13 if x11Mode then "linux-x11"
14 else if qtMode then "linux-qt4"
15 else if stdenv.hostPlatform.isLinux then "linux"
16 else if stdenv.hostPlatform.isDarwin then "macosx10.14"
17 # We probably want something different for Darwin
19 userDir = "~/.config/nethack";
20 binPath = lib.makeBinPath [ coreutils less ];
22 in stdenv.mkDerivation rec {
24 pname = if x11Mode then "nethack-x11"
25 else if qtMode then "nethack-qt"
29 url = "https://nethack.org/download/${version}/nethack-${lib.replaceStrings ["."] [""] version}-src.tgz";
30 sha256 = "sha256-mM9n323r+WaKYXRaqEwJvKs2Ll0z9blE7FFV1E0qrLI=";
33 buildInputs = [ ncurses ]
34 ++ lib.optionals x11Mode [ libXaw libXext libXpm ]
35 ++ lib.optionals qtMode [ gzip qt5.qtbase.bin qt5.qtmultimedia.bin ];
37 nativeBuildInputs = [ flex bison copyDesktopItems ]
38 ++ lib.optionals x11Mode [ mkfontdir bdftopcf ]
39 ++ lib.optionals qtMode [
40 pkg-config mkfontdir qt5.qtbase.dev
41 qt5.qtmultimedia.dev qt5.wrapQtAppsHook
45 makeFlags = [ "PREFIX=$(out)" ];
48 sed -e '/^ *cd /d' -i sys/unix/nethack.sh
50 -e 's/^YACC *=.*/YACC = bison -y/' \
51 -e 's/^LEX *=.*/LEX = flex/' \
52 -i sys/unix/Makefile.utl
54 -e 's,^WINQT4LIB =.*,WINQT4LIB = `pkg-config Qt5Gui --libs` \\\
55 `pkg-config Qt5Widgets --libs` \\\
56 `pkg-config Qt5Multimedia --libs`,' \
57 -i sys/unix/Makefile.src
59 -e 's,^CFLAGS=-g,CFLAGS=,' \
60 -e 's,/bin/gzip,${gzip}/bin/gzip,g' \
61 -e 's,^WINTTYLIB=.*,WINTTYLIB=-lncurses,' \
62 -i sys/unix/hints/linux
64 -e 's,^#WANT_WIN_CURSES=1$,WANT_WIN_CURSES=1,' \
65 -e 's,^CC=.*$,CC=${stdenv.cc.targetPrefix}cc,' \
66 -e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \
67 -e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \
68 -e 's,^CFLAGS=-g,CFLAGS=,' \
69 -i sys/unix/hints/macosx10.14
70 sed -e '/define CHDIR/d' -i include/config.h
71 ${lib.optionalString qtMode ''
73 -e 's,^QTDIR *=.*,QTDIR=${qt5.qtbase.dev},' \
74 -e 's,CFLAGS.*QtGui.*,CFLAGS += `pkg-config Qt5Gui --cflags`,' \
75 -e 's,CFLAGS+=-DCOMPRESS.*,CFLAGS+=-DCOMPRESS=\\"${gzip}/bin/gzip\\" \\\
76 -DCOMPRESS_EXTENSION=\\".gz\\",' \
78 -i sys/unix/hints/linux-qt4
80 ${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform)
81 # If we're cross-compiling, replace the paths to the data generation tools
82 # with the ones from the build platform's nethack package, since we can't
83 # run the ones we've built here.
85 ${buildPackages.perl}/bin/perl -p \
86 -e 's,[a-z./]+/(makedefs|dgn_comp|lev_comp|dlb)(?!\.),${buildPackages.nethack}/libexec/nethack/\1,g' \
87 -i sys/unix/Makefile.*
89 sed -i -e '/rm -f $(MAKEDEFS)/d' sys/unix/Makefile.src
90 # Fix building on darwin where otherwise __has_attribute fails with an empty parameter
91 sed -e 's/define __warn_unused_result__ .*/define __warn_unused_result__ __unused__/' -i include/tradstdc.h
92 sed -e 's/define warn_unused_result .*/define warn_unused_result __unused__/' -i include/tradstdc.h
97 ${lib.optionalString (platform == "unix") ''
98 sh setup.sh hints/${unixHint}
103 # https://github.com/NixOS/nixpkgs/issues/294751
104 enableParallelBuilding = false;
106 preFixup = lib.optionalString qtMode ''
107 wrapQtApp "$out/games/nethack"
111 mkdir -p $out/games/lib/nethackuserdir
112 for i in xlogfile logfile perm record save; do
113 mv $out/games/lib/nethackdir/$i $out/games/lib/nethackuserdir
117 cat <<EOF >$out/bin/nethack
118 #! ${stdenv.shell} -e
119 PATH=${binPath}:\$PATH
121 if [ ! -d ${userDir} ]; then
123 cp -r $out/games/lib/nethackuserdir/* ${userDir}
124 chmod -R +w ${userDir}
135 for i in ${userDir}/*; do
136 ln -s \$i \$(basename \$i)
138 for i in $out/games/lib/nethackdir/*; do
139 ln -s \$i \$(basename \$i)
143 chmod +x $out/bin/nethack
144 ${lib.optionalString x11Mode "mv $out/bin/nethack $out/bin/nethack-x11"}
145 ${lib.optionalString qtMode "mv $out/bin/nethack $out/bin/nethack-qt"}
146 install -Dm 555 util/{makedefs,dgn_comp,lev_comp} -t $out/libexec/nethack/
147 ${lib.optionalString (!(x11Mode || qtMode)) "install -Dm 555 util/dlb -t $out/libexec/nethack/"}
154 if x11Mode then "nethack-x11"
155 else if qtMode then "nethack-qt"
158 desktopName = "NetHack";
159 comment = "NetHack is a single player dungeon exploration game";
160 categories = [ "Game" "ActionGame" ];
165 description = "Rogue-like game";
166 homepage = "http://nethack.org/";
168 platforms = if x11Mode then platforms.linux else platforms.unix;
169 maintainers = with maintainers; [ abbradar ];
170 mainProgram = "nethack";