2023-02-18 13:33:42 +00:00
|
|
|
{ stdenv, lib, fetchurl, coreutils, ncurses, gzip, flex, bison
|
2019-07-05 15:42:08 +00:00
|
|
|
, less
|
2018-09-20 17:32:36 +00:00
|
|
|
, buildPackages
|
2021-01-17 05:49:22 +00:00
|
|
|
, x11Mode ? false, qtMode ? false, libXaw, libXext, libXpm, bdftopcf, mkfontdir, pkg-config, qt5
|
2024-01-26 19:25:13 +00:00
|
|
|
, copyDesktopItems, makeDesktopItem
|
2018-06-29 12:21:56 +00:00
|
|
|
}:
|
2015-06-29 11:19:12 +00:00
|
|
|
|
2015-12-08 14:45:44 +00:00
|
|
|
let
|
|
|
|
platform =
|
2018-03-09 23:40:51 +00:00
|
|
|
if stdenv.hostPlatform.isUnix then "unix"
|
2018-08-20 19:11:29 +00:00
|
|
|
else throw "Unknown platform for NetHack: ${stdenv.hostPlatform.system}";
|
2015-12-08 14:45:44 +00:00
|
|
|
unixHint =
|
2018-06-29 12:21:56 +00:00
|
|
|
if x11Mode then "linux-x11"
|
2018-07-15 06:18:55 +00:00
|
|
|
else if qtMode then "linux-qt4"
|
2018-06-29 12:21:56 +00:00
|
|
|
else if stdenv.hostPlatform.isLinux then "linux"
|
2018-03-09 23:40:51 +00:00
|
|
|
else if stdenv.hostPlatform.isDarwin then "macosx10.10"
|
2015-12-08 14:45:44 +00:00
|
|
|
# We probably want something different for Darwin
|
|
|
|
else "unix";
|
2015-12-08 15:10:53 +00:00
|
|
|
userDir = "~/.config/nethack";
|
2017-04-06 13:27:36 +00:00
|
|
|
binPath = lib.makeBinPath [ coreutils less ];
|
2015-12-08 14:45:44 +00:00
|
|
|
|
2018-07-15 06:18:55 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
2023-02-18 13:33:42 +00:00
|
|
|
version = "3.6.7";
|
2022-01-11 12:50:16 +00:00
|
|
|
pname = if x11Mode then "nethack-x11"
|
|
|
|
else if qtMode then "nethack-qt"
|
|
|
|
else "nethack";
|
2015-06-29 11:19:12 +00:00
|
|
|
|
2009-05-12 04:27:10 +00:00
|
|
|
src = fetchurl {
|
2020-03-21 21:06:24 +00:00
|
|
|
url = "https://nethack.org/download/${version}/nethack-${lib.replaceStrings ["."] [""] version}-src.tgz";
|
2023-02-18 13:33:42 +00:00
|
|
|
sha256 = "sha256-mM9n323r+WaKYXRaqEwJvKs2Ll0z9blE7FFV1E0qrLI=";
|
2009-05-12 04:27:10 +00:00
|
|
|
};
|
|
|
|
|
2018-07-15 06:18:55 +00:00
|
|
|
buildInputs = [ ncurses ]
|
2019-05-10 01:44:18 +00:00
|
|
|
++ lib.optionals x11Mode [ libXaw libXext libXpm ]
|
2018-07-15 06:18:55 +00:00
|
|
|
++ lib.optionals qtMode [ gzip qt5.qtbase.bin qt5.qtmultimedia.bin ];
|
2015-06-29 11:19:12 +00:00
|
|
|
|
2024-01-26 19:25:13 +00:00
|
|
|
nativeBuildInputs = [ flex bison copyDesktopItems ]
|
2018-09-20 18:01:36 +00:00
|
|
|
++ lib.optionals x11Mode [ mkfontdir bdftopcf ]
|
2018-07-15 06:18:55 +00:00
|
|
|
++ lib.optionals qtMode [
|
2021-01-17 05:49:22 +00:00
|
|
|
pkg-config mkfontdir qt5.qtbase.dev
|
2019-07-05 15:42:08 +00:00
|
|
|
qt5.qtmultimedia.dev qt5.wrapQtAppsHook
|
2018-09-20 18:01:36 +00:00
|
|
|
bdftopcf
|
2018-07-15 06:18:55 +00:00
|
|
|
];
|
2009-05-12 04:27:10 +00:00
|
|
|
|
2015-12-08 14:45:44 +00:00
|
|
|
makeFlags = [ "PREFIX=$(out)" ];
|
2009-05-12 04:27:10 +00:00
|
|
|
|
2018-08-08 15:36:21 +00:00
|
|
|
postPatch = ''
|
2016-02-29 03:04:23 +00:00
|
|
|
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
|
2018-07-15 06:18:55 +00:00
|
|
|
sed \
|
|
|
|
-e 's,^WINQT4LIB =.*,WINQT4LIB = `pkg-config Qt5Gui --libs` \\\
|
|
|
|
`pkg-config Qt5Widgets --libs` \\\
|
|
|
|
`pkg-config Qt5Multimedia --libs`,' \
|
|
|
|
-i sys/unix/Makefile.src
|
2016-02-29 03:04:23 +00:00
|
|
|
sed \
|
2018-08-08 15:36:21 +00:00
|
|
|
-e 's,^CFLAGS=-g,CFLAGS=,' \
|
2016-02-29 03:04:23 +00:00
|
|
|
-e 's,/bin/gzip,${gzip}/bin/gzip,g' \
|
|
|
|
-e 's,^WINTTYLIB=.*,WINTTYLIB=-lncurses,' \
|
|
|
|
-i sys/unix/hints/linux
|
|
|
|
sed \
|
2024-02-20 13:36:19 +00:00
|
|
|
-e 's,^#WANT_WIN_CURSES=1$,WANT_WIN_CURSES=1,' \
|
2021-02-16 11:48:46 +00:00
|
|
|
-e 's,^CC=.*$,CC=${stdenv.cc.targetPrefix}cc,' \
|
2016-02-29 03:04:23 +00:00
|
|
|
-e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \
|
|
|
|
-e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \
|
2018-08-08 15:36:21 +00:00
|
|
|
-e 's,^CFLAGS=-g,CFLAGS=,' \
|
2016-02-29 03:04:23 +00:00
|
|
|
-i sys/unix/hints/macosx10.10
|
|
|
|
sed -e '/define CHDIR/d' -i include/config.h
|
2018-09-19 17:30:09 +00:00
|
|
|
${lib.optionalString qtMode ''
|
2018-07-15 06:18:55 +00:00
|
|
|
sed \
|
|
|
|
-e 's,^QTDIR *=.*,QTDIR=${qt5.qtbase.dev},' \
|
|
|
|
-e 's,CFLAGS.*QtGui.*,CFLAGS += `pkg-config Qt5Gui --cflags`,' \
|
|
|
|
-e 's,CFLAGS+=-DCOMPRESS.*,CFLAGS+=-DCOMPRESS=\\"${gzip}/bin/gzip\\" \\\
|
|
|
|
-DCOMPRESS_EXTENSION=\\".gz\\",' \
|
2019-05-10 01:44:18 +00:00
|
|
|
-e 's,moc-qt4,moc,' \
|
2018-07-15 06:18:55 +00:00
|
|
|
-i sys/unix/hints/linux-qt4
|
2018-09-19 17:30:09 +00:00
|
|
|
''}
|
2018-09-20 17:47:13 +00:00
|
|
|
${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform)
|
|
|
|
# If we're cross-compiling, replace the paths to the data generation tools
|
|
|
|
# with the ones from the build platform's nethack package, since we can't
|
|
|
|
# run the ones we've built here.
|
|
|
|
''
|
2018-09-20 17:32:36 +00:00
|
|
|
${buildPackages.perl}/bin/perl -p \
|
|
|
|
-e 's,[a-z./]+/(makedefs|dgn_comp|lev_comp|dlb)(?!\.),${buildPackages.nethack}/libexec/nethack/\1,g' \
|
|
|
|
-i sys/unix/Makefile.*
|
|
|
|
''}
|
|
|
|
sed -i -e '/rm -f $(MAKEDEFS)/d' sys/unix/Makefile.src
|
2023-03-21 03:00:04 +00:00
|
|
|
# Fix building on darwin where otherwise __has_attribute fails with an empty parameter
|
|
|
|
sed -e 's/define __warn_unused_result__ .*/define __warn_unused_result__ __unused__/' -i include/tradstdc.h
|
|
|
|
sed -e 's/define warn_unused_result .*/define warn_unused_result __unused__/' -i include/tradstdc.h
|
2016-02-29 03:04:23 +00:00
|
|
|
'';
|
|
|
|
|
2015-12-08 14:45:44 +00:00
|
|
|
configurePhase = ''
|
2018-08-08 15:36:21 +00:00
|
|
|
pushd sys/${platform}
|
2015-12-08 14:45:44 +00:00
|
|
|
${lib.optionalString (platform == "unix") ''
|
|
|
|
sh setup.sh hints/${unixHint}
|
|
|
|
''}
|
2018-08-08 15:36:21 +00:00
|
|
|
popd
|
2015-06-29 11:19:12 +00:00
|
|
|
'';
|
|
|
|
|
2024-03-18 04:57:31 +00:00
|
|
|
# https://github.com/NixOS/nixpkgs/issues/294751
|
|
|
|
enableParallelBuilding = false;
|
2018-09-20 17:32:36 +00:00
|
|
|
|
2021-01-15 04:31:39 +00:00
|
|
|
preFixup = lib.optionalString qtMode ''
|
2019-07-05 15:42:08 +00:00
|
|
|
wrapQtApp "$out/games/nethack"
|
|
|
|
'';
|
|
|
|
|
2015-06-29 11:19:12 +00:00
|
|
|
postInstall = ''
|
2015-12-08 14:45:44 +00:00
|
|
|
mkdir -p $out/games/lib/nethackuserdir
|
2016-06-03 06:46:34 +00:00
|
|
|
for i in xlogfile logfile perm record save; do
|
2015-12-08 14:45:44 +00:00
|
|
|
mv $out/games/lib/nethackdir/$i $out/games/lib/nethackuserdir
|
2015-06-29 11:19:12 +00:00
|
|
|
done
|
|
|
|
|
2012-01-18 20:16:00 +00:00
|
|
|
mkdir -p $out/bin
|
2015-06-29 11:19:12 +00:00
|
|
|
cat <<EOF >$out/bin/nethack
|
2015-12-08 15:10:53 +00:00
|
|
|
#! ${stdenv.shell} -e
|
2017-04-06 13:27:36 +00:00
|
|
|
PATH=${binPath}:\$PATH
|
2015-06-29 11:19:12 +00:00
|
|
|
|
2015-12-08 15:10:53 +00:00
|
|
|
if [ ! -d ${userDir} ]; then
|
|
|
|
mkdir -p ${userDir}
|
|
|
|
cp -r $out/games/lib/nethackuserdir/* ${userDir}
|
|
|
|
chmod -R +w ${userDir}
|
|
|
|
fi
|
2015-06-29 11:19:12 +00:00
|
|
|
|
2016-02-29 03:04:23 +00:00
|
|
|
RUNDIR=\$(mktemp -d)
|
2015-06-29 11:19:12 +00:00
|
|
|
|
2015-12-08 15:10:53 +00: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 11:19:12 +00:00
|
|
|
EOF
|
|
|
|
chmod +x $out/bin/nethack
|
2018-06-29 12:21:56 +00:00
|
|
|
${lib.optionalString x11Mode "mv $out/bin/nethack $out/bin/nethack-x11"}
|
2018-07-15 06:18:55 +00:00
|
|
|
${lib.optionalString qtMode "mv $out/bin/nethack $out/bin/nethack-qt"}
|
2018-09-20 18:01:53 +00:00
|
|
|
install -Dm 555 util/{makedefs,dgn_comp,lev_comp} -t $out/libexec/nethack/
|
|
|
|
${lib.optionalString (!(x11Mode || qtMode)) "install -Dm 555 util/dlb -t $out/libexec/nethack/"}
|
2015-06-29 11:19:12 +00:00
|
|
|
'';
|
|
|
|
|
2024-01-26 19:25:13 +00:00
|
|
|
desktopItems = [
|
|
|
|
(makeDesktopItem {
|
|
|
|
name = "NetHack";
|
|
|
|
exec =
|
|
|
|
if x11Mode then "nethack-x11"
|
|
|
|
else if qtMode then "nethack-qt"
|
|
|
|
else "nethack";
|
|
|
|
icon = "nethack";
|
|
|
|
desktopName = "NetHack";
|
|
|
|
comment = "NetHack is a single player dungeon exploration game";
|
|
|
|
categories = [ "Game" "ActionGame" ];
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2015-06-29 11:19:12 +00:00
|
|
|
description = "Rogue-like game";
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "http://nethack.org/";
|
2015-06-29 11:19:12 +00:00
|
|
|
license = "nethack";
|
2018-06-29 12:21:56 +00:00
|
|
|
platforms = if x11Mode then platforms.linux else platforms.unix;
|
2015-06-29 11:19:12 +00:00
|
|
|
maintainers = with maintainers; [ abbradar ];
|
2024-01-26 19:25:13 +00:00
|
|
|
mainProgram = "nethack";
|
2009-05-12 04:27:10 +00:00
|
|
|
};
|
|
|
|
}
|