142 lines
3.1 KiB
Nix
142 lines
3.1 KiB
Nix
{
|
|
src,
|
|
withRuNethackMemes ? false,
|
|
|
|
coreutils,
|
|
darwin,
|
|
fetchzip,
|
|
stdenv,
|
|
ncurses,
|
|
groff,
|
|
lib,
|
|
gzip,
|
|
gnugrep,
|
|
bash,
|
|
pkg-config,
|
|
pkgs,
|
|
# pkgs ? import <nixpkgs> {}
|
|
}:
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
pname = "nethack";
|
|
version = "3.7-git";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
owner = "NetHack";
|
|
repo = "NetHack";
|
|
rev = "0f01260605c9393068e07a308840a9b6f8864aa9";
|
|
sha256 = "0d193ycd5yd1sgg64m6w7gqjm8vmfx8vsmrf6vi19idhj6zch72x";
|
|
};
|
|
|
|
luaVersion = "5.4.6";
|
|
luaTarballHash = "sha256-K2dM3q69YuOhlKKE9qTcHFJUVhjlRPxQtKB8ZQOpAyE=";
|
|
luaSrc = fetchzip {
|
|
name = "lua-src";
|
|
url = "https://www.lua.org/ftp/lua-${finalAttrs.luaVersion}.tar.gz";
|
|
hash = finalAttrs.luaTarballHash;
|
|
};
|
|
|
|
platformHint =
|
|
{
|
|
"aarch64-darwin" = "macOS";
|
|
"x86_64-linux" = "linux";
|
|
}
|
|
.${stdenv.hostPlatform.system} or (throw "Unsupported platform: ${stdenv.hostPlatform.system}");
|
|
|
|
#inherit src;
|
|
|
|
prePatch = ''
|
|
mkdir -p ./lib
|
|
cp -r --no-preserve=mode ${finalAttrs.luaSrc} ./lib/lua-${finalAttrs.luaVersion}
|
|
'';
|
|
|
|
buildInputs = [ ncurses ];
|
|
|
|
nativeBuildInputs = [
|
|
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/${finalAttrs.platformHint}.370
|
|
|
|
${lib.optionalString stdenv.hostPlatform.isDarwin ''
|
|
substituteInPlace sys/unix/hints/${finalAttrs.platformHint}.370 \
|
|
--replace-fail "/usr/bin/true" "${coreutils}/bin/true" \
|
|
--replace-fail "which" "${darwin.shell_cmds}/bin/which"
|
|
''}
|
|
|
|
sed \
|
|
-e '/^GDBPATH=/d' \
|
|
-e '/^PANICTRACE_GDB=/s/1/0/' \
|
|
-e '/^GREPPATH=/s:=.*:=${lib.getExe gnugrep}:' \
|
|
-e '/^WIZARDS/s/=.*/=*/' \
|
|
-i sys/unix/sysconf
|
|
|
|
${lib.optionalString withRuNethackMemes ''
|
|
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/${finalAttrs.platformHint}.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
|
|
'';
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
NIX_CFLAGS_COMPILE = "-DUSE_DARKGRAY";
|
|
|
|
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";
|
|
};
|
|
})
|
|
|