125 lines
2.5 KiB
Plaintext

{
src,
fetchzip,
stdenv,
ncurses,
util-linux,
groff,
lib,
gzip,
gnugrep,
bash,
pkg-config,
pkgs ? import <nixpkgs> {}
}:
stdenv.mkDerivation (finalAttrs: {
pname = "nethack";
version = "3.7-git";
lua-version = "5.4.6";
lua-tarball-hash = "sha256-K2dM3q69YuOhlKKE9qTcHFJUVhjlRPxQtKB8ZQOpAyE=";
srcs = [
src
(fetchzip {
name = "lua-src";
url = "https://www.lua.org/ftp/lua-${finalAttrs.lua-version}.tar.gz";
hash = finalAttrs.lua-tarball-hash;
})
];
postUnpack = ''
ls && exit 1
mkdir -p ${finalAttrs.sourceRoot}/lib/
cp -r --no-preserve=mode lua-src ${finalAttrs.sourceRoot}/lib/lua-${finalAttrs.lua-version}
'';
src = pkgs.fetchFromGitHub {
owner = "NetHack";
repo = "NetHack";
rev = "0f01260605c9393068e07a308840a9b6f8864aa9";
sha256 = "0d193ycd5yd1sgg64m6w7gqjm8vmfx8vsmrf6vi19idhj6zch72x";
};
sourceRoot = src.name;
buildInputs = [ ncurses ];
nativeBuildInputs = [
util-linux
groff
pkg-config
];
postPatch = ''
sed \
-e '/^GIT_HASH/d' \
-e '/^GIT_BRANCH/d' \
-e '/^SHELLDIR/d' \
-e '/-DCOMPRESS/s:/bin/gzip:${lib.getExe' gzip "gzip"}:' \
-i sys/unix/hints/linux.370
sed \
-e '/^GDBPATH=/d' \
-e '/^PANICTRACE_GDB=/s/1/0/' \
-e '/^GREPPATH=/s:=.*:=${lib.getExe gnugrep}:' \
-e '/^WIZARDS/s/=.*/=*/' \
-i sys/unix/sysconf
sed \
-e 's/\bluckstone\b/laccstone/g' \
-e 's/\bhiss\b/zHz/g' \
-e 's/\bsouls\b/Russel Souls/g' \
-i $(find -type f)
'';
patches = [ ./unixconf.patch ];
configurePhase = ''
sys/unix/setup.sh sys/unix/hints/linux.370
'';
postInstall = ''
mkdir $out/bin
cat > $out/bin/nethack << EOF
#! ${lib.getExe bash}
if [ -z "\$HOME" ]; then
echo "Home directory must be set to play NetHack" >&2
exit 1
fi
export NETHACKVARDIR="\$HOME/.local/share/nethack"
if [ -e "\$NETHACKVARDIR" ]; then
if [ ! -d "\$NETHACKVARDIR" ]; then
echo "\$NETHACKVARDIR must not be something that is not a directory" >&2
exit 1
fi
else
mkdir -p "\$NETHACKVARDIR"
cp -r $out/lib/nethack/vardir/* "\$NETHACKVARDIR"
chmod -R +w "\$NETHACKVARDIR"/*
fi
$out/lib/nethack/nethack \$@
EOF
chmod +x $out/bin/nethack
'';
makeFlags = [
"GIT=0"
"PREFIX=$(out)"
"HACKDIR=$(out)/lib/nethack"
"VARDIR=$(out)/lib/nethack/vardir"
"WANT_WIN_TTY=1"
"WANT_WIN_CURSES=1"
];
meta = {
mainProgram = "nethack";
};
})