From 052b7cc9adb0b0d1107e99a2812ff7d2922d375f Mon Sep 17 00:00:00 2001 From: Palmer Cox
Date: Fri, 8 May 2026 03:55:11 +0000
Subject: [PATCH] nethack: Support cross compilation
Major caveat: x11 and qt don't work.
The main idea is to update the Makefiles with references to the correct
toolchain by replacing direct executable names with references to the
appropriate environment variables.
We also update the makefiles to use tools from the buildPlatform's
version of Nethack. As part of this, we have to final the install phase
to install these as part of native builds.
Finally, we fix an issue with the wrapper script where it would use the
build platform's version of bash as opposed to the host platforms.
---
pkgs/by-name/ne/nethack/package.nix | 36 ++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/pkgs/by-name/ne/nethack/package.nix b/pkgs/by-name/ne/nethack/package.nix
index 11a26a67f6b1..43f3b46dca9f 100644
--- a/pkgs/by-name/ne/nethack/package.nix
+++ b/pkgs/by-name/ne/nethack/package.nix
@@ -7,6 +7,8 @@
ncurses,
gzip,
less,
+ bash,
+ buildPackages,
x11Mode ? false,
qtMode ? false,
libxaw,
@@ -140,6 +142,30 @@ stdenv.mkDerivation (finalAttrs: {
sed -e '/define CHDIR/d' \
-e '/define ENHANCED_SYMBOLS/d' \
-i include/config.h
+ sed \
+ -e 's,AR=.*,AR := $(AR) rcu,' \
+ -e 's,RANLIB=.*,RANLIB := $(RANLIB),' \
+ -i lib/lua-5.4.8/src/Makefile
+ sed \
+ -e 's,AR =.*,AR := $(AR),' \
+ -i sys/unix/Makefile.src
+ ${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.
+ ''
+ sed \
+ -e 's, ../util/makedefs,,' \
+ -e 's,\t../util/makedefs,\t${buildPackages.nethack}/libexec/nethack/makedefs,' \
+ -e 's,\t../util/dlb,\t${buildPackages.nethack}/libexec/nethack/dlb,' \
+ -e 's,../util/dlb cf nhdat,${buildPackages.nethack}/libexec/nethack/dlb cf nhdat,' \
+ -e 's,pkg-config,$(PKG_CONFIG),' \
+ -i sys/unix/Makefile.*
+ sed \
+ -e 's,pkg-config,$(PKG_CONFIG),' \
+ -i sys/unix/hints/linux.500
+ ''
+ }
'';
configurePhase = ''
@@ -163,7 +189,7 @@ stdenv.mkDerivation (finalAttrs: {
mkdir -p $out/bin
cat <