nethack, nethack-{x11,qt}: move to by-name, modernize, adopt (#451120)

This commit is contained in:
Yohann Boniface
2025-10-11 23:28:54 +00:00
committed by GitHub
4 changed files with 32 additions and 24 deletions

View File

@@ -0,0 +1,7 @@
{
nethack,
}:
nethack.override {
qtMode = true;
}

View File

@@ -0,0 +1,7 @@
{
nethack,
}:
nethack.override {
x11Mode = true;
}

View File

@@ -5,6 +5,7 @@
coreutils, coreutils,
ncurses, ncurses,
gzip, gzip,
gccStdenv,
flex, flex,
bison, bison,
less, less,
@@ -23,19 +24,21 @@
}: }:
let let
stdenvUsed = if qtMode then gccStdenv else stdenv;
platform = platform =
if stdenv.hostPlatform.isUnix then if stdenvUsed.hostPlatform.isUnix then
"unix" "unix"
else else
throw "Unknown platform for NetHack: ${stdenv.hostPlatform.system}"; throw "Unknown platform for NetHack: ${stdenvUsed.hostPlatform.system}";
unixHint = unixHint =
if x11Mode then if x11Mode then
"linux-x11" "linux-x11"
else if qtMode then else if qtMode then
"linux-qt4" "linux-qt4"
else if stdenv.hostPlatform.isLinux then else if stdenvUsed.hostPlatform.isLinux then
"linux" "linux"
else if stdenv.hostPlatform.isDarwin then else if stdenvUsed.hostPlatform.isDarwin then
"macosx10.14" "macosx10.14"
# We probably want something different for Darwin # We probably want something different for Darwin
else else
@@ -47,7 +50,7 @@ let
]; ];
in in
stdenv.mkDerivation rec { stdenvUsed.mkDerivation (finalAttrs: {
version = "3.6.7"; version = "3.6.7";
pname = pname =
if x11Mode then if x11Mode then
@@ -58,10 +61,10 @@ stdenv.mkDerivation rec {
"nethack"; "nethack";
src = fetchurl { src = fetchurl {
url = "https://nethack.org/download/${version}/nethack-${ url = "https://nethack.org/download/${finalAttrs.version}/nethack-${
lib.replaceStrings [ "." ] [ "" ] version lib.replaceStrings [ "." ] [ "" ] finalAttrs.version
}-src.tgz"; }-src.tgz";
sha256 = "sha256-mM9n323r+WaKYXRaqEwJvKs2Ll0z9blE7FFV1E0qrLI="; hash = "sha256-mM9n323r+WaKYXRaqEwJvKs2Ll0z9blE7FFV1E0qrLI=";
}; };
buildInputs = [ buildInputs = [
@@ -116,7 +119,7 @@ stdenv.mkDerivation rec {
-i sys/unix/hints/linux -i sys/unix/hints/linux
sed \ sed \
-e 's,^#WANT_WIN_CURSES=1$,WANT_WIN_CURSES=1,' \ -e 's,^#WANT_WIN_CURSES=1$,WANT_WIN_CURSES=1,' \
-e 's,^CC=.*$,CC=${stdenv.cc.targetPrefix}cc,' \ -e 's,^CC=.*$,CC=${stdenvUsed.cc.targetPrefix}cc,' \
-e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \ -e 's,^HACKDIR=.*$,HACKDIR=\$(PREFIX)/games/lib/\$(GAME)dir,' \
-e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \ -e 's,^SHELLDIR=.*$,SHELLDIR=\$(PREFIX)/games,' \
-e 's,^CFLAGS=-g,CFLAGS=,' \ -e 's,^CFLAGS=-g,CFLAGS=,' \
@@ -132,7 +135,7 @@ stdenv.mkDerivation rec {
-e 's,moc-qt4,moc,' \ -e 's,moc-qt4,moc,' \
-i sys/unix/hints/linux-qt4 -i sys/unix/hints/linux-qt4
''} ''}
${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ${lib.optionalString (stdenvUsed.buildPlatform != stdenvUsed.hostPlatform)
# If we're cross-compiling, replace the paths to the data generation tools # 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 # with the ones from the build platform's nethack package, since we can't
# run the ones we've built here. # run the ones we've built here.
@@ -171,7 +174,7 @@ stdenv.mkDerivation rec {
mkdir -p $out/bin mkdir -p $out/bin
cat <<EOF >$out/bin/nethack cat <<EOF >$out/bin/nethack
#! ${stdenv.shell} -e #! ${stdenvUsed.shell} -e
PATH=${binPath}:\$PATH PATH=${binPath}:\$PATH
if [ ! -d ${userDir} ]; then if [ ! -d ${userDir} ]; then
@@ -228,12 +231,12 @@ stdenv.mkDerivation rec {
}) })
]; ];
meta = with lib; { meta = {
description = "Rogue-like game"; description = "Rogue-like game";
homepage = "http://nethack.org/"; homepage = "http://nethack.org/";
license = lib.licenses.ngpl; license = lib.licenses.ngpl;
platforms = if x11Mode then platforms.linux else platforms.unix; platforms = if x11Mode then lib.platforms.linux else lib.platforms.unix;
maintainers = [ ]; maintainers = with lib.maintainers; [ iedame ];
mainProgram = "nethack"; mainProgram = "nethack";
}; };
} })

View File

@@ -13506,15 +13506,6 @@ with pkgs;
blightmud-tts = callPackage ../games/blightmud { withTTS = true; }; blightmud-tts = callPackage ../games/blightmud { withTTS = true; };
nethack = callPackage ../games/nethack { };
nethack-qt = callPackage ../games/nethack {
qtMode = true;
stdenv = gccStdenv;
};
nethack-x11 = callPackage ../games/nethack { x11Mode = true; };
npush = callPackage ../games/npush { }; npush = callPackage ../games/npush { };
run-npush = callPackage ../games/npush/run.nix { }; run-npush = callPackage ../games/npush/run.nix { };