unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] gnu: Add nethack.
@ 2016-05-31 21:56 Kei Kebreau
  2016-06-04 21:15 ` Ludovic Courtès
  0 siblings, 1 reply; 10+ messages in thread
From: Kei Kebreau @ 2016-05-31 21:56 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 242 bytes --]

NetHack finally works, though I'd like others to review the
implementation. This is also my first time adding a .patch file to the
repository, so advice along those lines would be appreciated.

-- 
Kei (GPG Key: 4096R/E6A5EE3C19467A0D)

[-- Attachment #1.2: 0001-gnu-Add-nethack.patch --]
[-- Type: text/plain, Size: 8574 bytes --]

From b728e078408f17136e8a4c3344b606e8f152b9e4 Mon Sep 17 00:00:00 2001
From: Kei Kebreau <kei@openmailbox.org>
Date: Tue, 31 May 2016 17:42:28 -0400
Subject: [PATCH] gnu: Add nethack.

* gnu/packages/games.scm (nethack): New variable.
---
 gnu/packages/games.scm                             | 98 ++++++++++++++++++++++
 ...thack-correct-directories-and-permissions.patch | 72 ++++++++++++++++
 2 files changed, 170 insertions(+)
 create mode 100644 gnu/packages/patches/nethack-correct-directories-and-permissions.patch

diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index fc16862..44afb87 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -49,10 +49,12 @@
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages backup)
   #:use-module (gnu packages base)
+  #:use-module (gnu packages bison)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages audio)
   #:use-module (gnu packages avahi)
   #:use-module (gnu packages boost)
+  #:use-module (gnu packages flex)
   #:use-module (gnu packages fribidi)
   #:use-module (gnu packages game-development)
   #:use-module (gnu packages gettext)
@@ -2243,3 +2245,99 @@ Red Eclipse provides fast paced and accessible gameplay.")
                      license:cc-by-sa3.0
                      license:cc-by3.0
                      license:cc0)))))
+
+(define-public nethack
+  (package
+    (name "nethack")
+    (version "3.6.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://sourceforge/" name "/" name "-"
+                                  (string-join (string-split version #\.) "")
+                                  "-src.tgz"))
+              (sha256
+               (base32
+                "12mi5kgqw3q029y57pkg3gnp930p7yvlqi118xxdif2qhj6nkphs"))
+              (patches
+               (search-patches
+                "nethack-correct-directories-and-permissions.patch"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f ; no check target
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'configure
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((out (assoc-ref outputs "out")))
+               (substitute* "sys/unix/hints/linux"
+                 (("^PREFIX=.*$")
+                  (string-append "PREFIX=" out "\n"))
+                 (("/bin/gzip") (which "gzip")))
+               (substitute* "sys/unix/setup.sh"
+                 (("/bin/sh") (which "bash"))))
+             (system* "sh" "sys/unix/setup.sh" "sys/unix/hints/linux")))
+         (add-after 'install 'move-state-files
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out")))
+               (mkdir (string-append out "/games/lib/nethack-state-files"))
+               (chdir (string-append out "/games/lib/nethackdir"))
+               (for-each (lambda (file)
+                           (system* "mv" file
+                                    (string-append
+                                     out "/games/lib/nethack-state-files")))
+                         '("logfile" "perm" "record" "save" "xlogfile")))))
+         (add-after 'move-state-files 'wrap-program
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (nethack-user-dir "~/.nethack"))
+               (mkdir bin)
+               (with-directory-excursion bin
+                 (call-with-output-file "nethack"
+                   (lambda (port)
+                     (format port "#!~a/bin/sh -e
+# Create NetHack directory in user's $HOME if it isn't there
+if [ ! -d ~a ]; then
+  mkdir -p ~a
+  cp -r ~a/* ~a
+  chmod -R +w ~a
+fi
+
+RUNDIR=$(mktemp -d)
+
+cleanup() {
+  rm -rf $RUNDIR
+}
+trap cleanup EXIT
+
+cd $RUNDIR
+for i in ~a/*; do
+  ln -s $i $(basename $i)
+done
+for i in ~a/*; do
+  ln -s $i $(basename $i)
+done
+./nethack~%"
+                             (assoc-ref inputs "bash") ;implicit input
+                             (string-append nethack-user-dir)
+                             (string-append nethack-user-dir)
+                             (string-append
+                              out "/games/lib/nethack-state-files")
+                             (string-append nethack-user-dir)
+                             (string-append nethack-user-dir)
+                             (string-append nethack-user-dir)
+                             (string-append out "/games/lib/nethackdir")
+                             (string-append out))))
+                 (chmod "nethack" #o555)))
+             #t)))))
+    (native-inputs
+     `(("bison" ,bison)
+       ("flex" ,flex)))
+    (inputs `(("ncurses" ,ncurses)))
+    (home-page "http://nethack.org")
+    (synopsis "Single player dungeon exploration game")
+    (description
+     "Nethack is a roguelike game that emphasizes discovery of details in the
+dungeon.  The random number generator provides an unlimited number of
+variations of the dungeon.")
+    (license (license:fsf-free "http://nethack.org/common/license.html"))))
diff --git a/gnu/packages/patches/nethack-correct-directories-and-permissions.patch b/gnu/packages/patches/nethack-correct-directories-and-permissions.patch
new file mode 100644
index 0000000..6f6d436
--- /dev/null
+++ b/gnu/packages/patches/nethack-correct-directories-and-permissions.patch
@@ -0,0 +1,72 @@
+diff -r -u nethack-3.6.0.orig/include/config.h nethack-3.6.0/include/config.h
+--- nethack-3.6.0.orig/include/config.h	2016-05-27 17:20:03.062318307 -0400
++++ nethack-3.6.0/include/config.h	2016-05-31 16:48:04.283642766 -0400
+@@ -308,7 +308,6 @@
+ #define INSURANCE /* allow crashed game recovery */
+ 
+ #ifndef MAC
+-#define CHDIR /* delete if no chdir() available */
+ #endif
+ 
+ #ifdef CHDIR
+diff -r -u nethack-3.6.0.orig/include/unixconf.h nethack-3.6.0/include/unixconf.h
+--- nethack-3.6.0.orig/include/unixconf.h	2016-05-27 17:20:03.062318307 -0400
++++ nethack-3.6.0/include/unixconf.h	2016-05-30 20:33:52.132273630 -0400
+@@ -36,7 +36,7 @@
+ #define NETWORK        /* if running on a networked system */
+                        /* e.g. Suns sharing a playground through NFS */
+ /* #define SUNOS4 */   /* SunOS 4.x */
+-/* #define LINUX */    /* Another Unix clone */
++#define LINUX          /* Another Unix clone */
+ /* #define CYGWIN32 */ /* Unix on Win32 -- use with case sensitive defines */
+ /* #define GENIX */    /* Yet Another Unix Clone */
+ /* #define HISX */     /* Bull Unix for XPS Machines */
+diff -r -u nethack-3.6.0.orig/sys/unix/Makefile.src nethack-3.6.0/sys/unix/Makefile.src
+--- nethack-3.6.0.orig/sys/unix/Makefile.src	2016-05-27 17:20:03.082318966 -0400
++++ nethack-3.6.0/sys/unix/Makefile.src	2016-05-27 17:42:47.183397931 -0400
+@@ -64,7 +64,7 @@
+ #	if you get setcgtty() warnings during execution, you are feeding gcc
+ #		a non-ANSI <sys/ioctl.h> -- either run fixincludes on it or use
+ #		-traditional in CFLAGS
+-# CC = gcc
++CC = gcc
+ #
+ #	For Bull DPX/2 systems at B.O.S. 2.0 or higher use the following:
+ #
+@@ -238,7 +238,7 @@
+ # WINTTYLIB = -ltermcap
+ # WINTTYLIB = -lcurses
+ # WINTTYLIB = -lcurses16
+-# WINTTYLIB = -lncurses
++WINTTYLIB = -lncurses
+ #WINTTYLIB = -ltermlib
+ #
+ # libraries for X11
+diff -r -u nethack-3.6.0.orig/sys/unix/Makefile.utl nethack-3.6.0/sys/unix/Makefile.utl
+--- nethack-3.6.0.orig/sys/unix/Makefile.utl	2016-05-27 17:20:03.082318966 -0400
++++ nethack-3.6.0/sys/unix/Makefile.utl	2016-05-27 20:01:54.605040799 -0400
+@@ -18,7 +18,7 @@
+ 
+ # if you are using gcc as your compiler,
+ #	uncomment the CC definition below if it's not in your environment
+-# CC = gcc
++CC = gcc
+ #
+ #	For Bull DPX/2 systems at B.O.S. 2.0 or higher use the following:
+ #
+@@ -104,11 +104,11 @@
+ 
+ # yacc/lex programs to use to generate *_comp.h, *_lex.c, and *_yacc.c.
+ # if, instead of yacc/lex you have bison/flex, comment/uncomment the following.
+-YACC     = yacc
+-LEX      = lex
+-# YACC     = bison -y
++# YACC     = yacc
++# LEX      = lex
++YACC     = bison -y
+ # YACC     = byacc
+-# LEX      = flex
++LEX      = flex
+ 
+ # these are the names of the output files from YACC/LEX. Under MS-DOS
+ # and similar systems, they may differ
-- 
2.7.4


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-05-31 21:56 [PATCH] gnu: Add nethack Kei Kebreau
@ 2016-06-04 21:15 ` Ludovic Courtès
  2016-06-06 20:25   ` Kei Kebreau
  0 siblings, 1 reply; 10+ messages in thread
From: Ludovic Courtès @ 2016-06-04 21:15 UTC (permalink / raw)
  To: Kei Kebreau; +Cc: guix-devel

Hi!

Kei Kebreau <kei@openmailbox.org> skribis:

> From b728e078408f17136e8a4c3344b606e8f152b9e4 Mon Sep 17 00:00:00 2001
> From: Kei Kebreau <kei@openmailbox.org>
> Date: Tue, 31 May 2016 17:42:28 -0400
> Subject: [PATCH] gnu: Add nethack.
>
> * gnu/packages/games.scm (nethack): New variable.

You need to mention the new .patch file here (see ‘git log’ for
examples.)

You also need to add the .patch file to gnu/local.mk, and to mention the
change to gnu/local.mk in the commit log.

[...]

> +         (replace 'configure
> +           (lambda* (#:key inputs outputs #:allow-other-keys)
> +             (let ((out (assoc-ref outputs "out")))
> +               (substitute* "sys/unix/hints/linux"
> +                 (("^PREFIX=.*$")
> +                  (string-append "PREFIX=" out "\n"))
> +                 (("/bin/gzip") (which "gzip")))
> +               (substitute* "sys/unix/setup.sh"
> +                 (("/bin/sh") (which "bash"))))
> +             (system* "sh" "sys/unix/setup.sh" "sys/unix/hints/linux")))

Should be: (zero? (system* …)), which returns #t on success (a phase
must return a true value to be considered successful.)

> +         (add-after 'install 'move-state-files
> +           (lambda* (#:key inputs outputs #:allow-other-keys)
> +             (let* ((out (assoc-ref outputs "out")))
> +               (mkdir (string-append out "/games/lib/nethack-state-files"))
> +               (chdir (string-append out "/games/lib/nethackdir"))
> +               (for-each (lambda (file)
> +                           (system* "mv" file
> +                                    (string-append
> +                                     out "/games/lib/nethack-state-files")))

Instead of using the ‘mv’ command (or any other Coreutils command, for
that matter), use the Scheme equivalent.  Here it would be:

  (install-file file directory)

Besides, “/games” is unusual in the file system hierarchy.  Usually,
state files go to the localstatedir, i.e., the var/PACKAGE subdirectory.

Thus, what about putting state files in OUT/var/nethack?

But again, OUT is immutable, so these files cannot be modified, so
they’re not really “state.”

> +                         '("logfile" "perm" "record" "save" "xlogfile")))))

For clarity, have the phase return #t.

> +         (add-after 'move-state-files 'wrap-program
> +           (lambda* (#:key inputs outputs #:allow-other-keys)
> +             (let* ((out (assoc-ref outputs "out"))
> +                    (bin (string-append out "/bin"))
> +                    (nethack-user-dir "~/.nethack"))
> +               (mkdir bin)
> +               (with-directory-excursion bin
> +                 (call-with-output-file "nethack"
> +                   (lambda (port)
> +                     (format port "#!~a/bin/sh -e
> +# Create NetHack directory in user's $HOME if it isn't there
> +if [ ! -d ~a ]; then
> +  mkdir -p ~a
> +  cp -r ~a/* ~a
> +  chmod -R +w ~a
> +fi
> +
> +RUNDIR=$(mktemp -d)
> +
> +cleanup() {
> +  rm -rf $RUNDIR
> +}
> +trap cleanup EXIT
> +
> +cd $RUNDIR
> +for i in ~a/*; do
> +  ln -s $i $(basename $i)
> +done
> +for i in ~a/*; do
> +  ln -s $i $(basename $i)
> +done
> +./nethack~%"

Do we really need this wrapper?  Can’t we instead take it as a patch
from Debian or something?  I’m not a fan of inline Bash code, and not
very confident of scripts that do ‘rm -rf’.  :-)


> +--- nethack-3.6.0.orig/include/config.h	2016-05-27 17:20:03.062318307 -0400
> ++++ nethack-3.6.0/include/config.h	2016-05-31 16:48:04.283642766 -0400

Patches must always start with a line or two indicating what they do and
what their upstream status or origin is.

> +@@ -308,7 +308,6 @@
> + #define INSURANCE /* allow crashed game recovery */
> + 
> + #ifndef MAC
> +-#define CHDIR /* delete if no chdir() available */
> + #endif

Why?

> +-# CC = gcc
> ++CC = gcc
> + #
> + #	For Bull DPX/2 systems at B.O.S. 2.0 or higher use the following:
> + #
> +@@ -104,11 +104,11 @@
> + 
> + # yacc/lex programs to use to generate *_comp.h, *_lex.c, and *_yacc.c.
> + # if, instead of yacc/lex you have bison/flex, comment/uncomment the following.
> +-YACC     = yacc
> +-LEX      = lex
> +-# YACC     = bison -y
> ++# YACC     = yacc
> ++# LEX      = lex
> ++YACC     = bison -y
> + # YACC     = byacc
> +-# LEX      = flex
> ++LEX      = flex

Would it work to, instead, do:

  #:make-flags '("CC=gcc" "LEX=flex" …)

If it does, I think it’s preferable.

Could you send an updated patch?

Thanks for working on this tricky package!  ;-)

Ludo’.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-04 21:15 ` Ludovic Courtès
@ 2016-06-06 20:25   ` Kei Kebreau
  2016-06-07 17:20     ` Leo Famulari
  0 siblings, 1 reply; 10+ messages in thread
From: Kei Kebreau @ 2016-06-06 20:25 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 5675 bytes --]

On Sat, 04 Jun 2016 23:15:57 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

> Hi!
> 
> Kei Kebreau <kei@openmailbox.org> skribis:
> 
> > From b728e078408f17136e8a4c3344b606e8f152b9e4 Mon Sep 17 00:00:00
> > 2001 From: Kei Kebreau <kei@openmailbox.org>
> > Date: Tue, 31 May 2016 17:42:28 -0400
> > Subject: [PATCH] gnu: Add nethack.
> >
> > * gnu/packages/games.scm (nethack): New variable.  
> 
> You need to mention the new .patch file here (see ‘git log’ for
> examples.)
> 
> You also need to add the .patch file to gnu/local.mk, and to mention
> the change to gnu/local.mk in the commit log.
> 
> [...]
> 
> > +         (replace 'configure
> > +           (lambda* (#:key inputs outputs #:allow-other-keys)
> > +             (let ((out (assoc-ref outputs "out")))
> > +               (substitute* "sys/unix/hints/linux"
> > +                 (("^PREFIX=.*$")
> > +                  (string-append "PREFIX=" out "\n"))
> > +                 (("/bin/gzip") (which "gzip")))
> > +               (substitute* "sys/unix/setup.sh"
> > +                 (("/bin/sh") (which "bash"))))
> > +             (system* "sh" "sys/unix/setup.sh"
> > "sys/unix/hints/linux")))  
> 
> Should be: (zero? (system* …)), which returns #t on success (a phase
> must return a true value to be considered successful.)
> 
> > +         (add-after 'install 'move-state-files
> > +           (lambda* (#:key inputs outputs #:allow-other-keys)
> > +             (let* ((out (assoc-ref outputs "out")))
> > +               (mkdir (string-append out
> > "/games/lib/nethack-state-files"))
> > +               (chdir (string-append out "/games/lib/nethackdir"))
> > +               (for-each (lambda (file)
> > +                           (system* "mv" file
> > +                                    (string-append
> > +                                     out
> > "/games/lib/nethack-state-files")))  
> 
> Instead of using the ‘mv’ command (or any other Coreutils command, for
> that matter), use the Scheme equivalent.  Here it would be:
> 
>   (install-file file directory)
> 
> Besides, “/games” is unusual in the file system hierarchy.  Usually,
> state files go to the localstatedir, i.e., the var/PACKAGE
> subdirectory.
> 
> Thus, what about putting state files in OUT/var/nethack?
> 
> But again, OUT is immutable, so these files cannot be modified, so
> they’re not really “state.”
> 
> > +                         '("logfile" "perm" "record" "save"
> > "xlogfile")))))  
> 
> For clarity, have the phase return #t.
> 
> > +         (add-after 'move-state-files 'wrap-program
> > +           (lambda* (#:key inputs outputs #:allow-other-keys)
> > +             (let* ((out (assoc-ref outputs "out"))
> > +                    (bin (string-append out "/bin"))
> > +                    (nethack-user-dir "~/.nethack"))
> > +               (mkdir bin)
> > +               (with-directory-excursion bin
> > +                 (call-with-output-file "nethack"
> > +                   (lambda (port)
> > +                     (format port "#!~a/bin/sh -e
> > +# Create NetHack directory in user's $HOME if it isn't there
> > +if [ ! -d ~a ]; then
> > +  mkdir -p ~a
> > +  cp -r ~a/* ~a
> > +  chmod -R +w ~a
> > +fi
> > +
> > +RUNDIR=$(mktemp -d)
> > +
> > +cleanup() {
> > +  rm -rf $RUNDIR
> > +}
> > +trap cleanup EXIT
> > +
> > +cd $RUNDIR
> > +for i in ~a/*; do
> > +  ln -s $i $(basename $i)
> > +done
> > +for i in ~a/*; do
> > +  ln -s $i $(basename $i)
> > +done
> > +./nethack~%"  
> 
> Do we really need this wrapper?  Can’t we instead take it as a patch
> from Debian or something?  I’m not a fan of inline Bash code, and not
> very confident of scripts that do ‘rm -rf’.  :-)
> 
> 
> > +--- nethack-3.6.0.orig/include/config.h	2016-05-27
> > 17:20:03.062318307 -0400 ++++ nethack-3.6.0/include/config.h
> > 2016-05-31 16:48:04.283642766 -0400  
> 
> Patches must always start with a line or two indicating what they do
> and what their upstream status or origin is.
> 
> > +@@ -308,7 +308,6 @@
> > + #define INSURANCE /* allow crashed game recovery */
> > + 
> > + #ifndef MAC
> > +-#define CHDIR /* delete if no chdir() available */
> > + #endif  
> 
> Why?
> 
> > +-# CC = gcc
> > ++CC = gcc
> > + #
> > + #	For Bull DPX/2 systems at B.O.S. 2.0 or higher use the
> > following:
> > + #
> > +@@ -104,11 +104,11 @@
> > + 
> > + # yacc/lex programs to use to generate *_comp.h, *_lex.c, and
> > *_yacc.c.
> > + # if, instead of yacc/lex you have bison/flex, comment/uncomment
> > the following. +-YACC     = yacc
> > +-LEX      = lex
> > +-# YACC     = bison -y
> > ++# YACC     = yacc
> > ++# LEX      = lex
> > ++YACC     = bison -y
> > + # YACC     = byacc
> > +-# LEX      = flex
> > ++LEX      = flex  
> 
> Would it work to, instead, do:
> 
>   #:make-flags '("CC=gcc" "LEX=flex" …)
> 
> If it does, I think it’s preferable.
> 
> Could you send an updated patch?
> 
> Thanks for working on this tricky package!  ;-)
> 
> Ludo’.

Unfortunately, Debian doesn't have any related patches because it's
state files are writable in the equivalent of our store directories. It
seems like the bash script will have to stay for the sake of
functionality unless someone comes up with something cleaner, though I
prefer to avoid them. Long ago, I lost a GNU/Linux installation to
"rm -rf"...

I've added comments to the patch file and replaced the calls to
coreutils with their Scheme equivalent (and cleaned up nethack's store
folder along the way).
-- 
Kei (GPG Key: 4096R/E6A5EE3C19467A0D)

[-- Attachment #1.2: 0001-gnu-Add-nethack.patch --]
[-- Type: text/plain, Size: 8853 bytes --]

From b33446b7c3b0b14816ff359747a8049f84295dfd Mon Sep 17 00:00:00 2001
From: Kei Kebreau <kei@openmailbox.org>
Date: Mon, 6 Jun 2016 15:56:45 -0400
Subject: [PATCH] gnu: Add nethack.

* gnu/packages/patches/nethack-correct-directories-and-permissions.patch:
New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/games.scm (nethack): New variable.
---
 gnu/local.mk                                       |   1 +
 gnu/packages/games.scm                             | 111 +++++++++++++++++++++
 ...thack-correct-directories-and-permissions.patch |  40 ++++++++
 3 files changed, 152 insertions(+)
 create mode 100644 gnu/packages/patches/nethack-correct-directories-and-permissions.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index c130901..c9facb9 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -636,6 +636,7 @@ dist_patch_DATA =						\
   gnu/packages/patches/mutt-store-references.patch		\
   gnu/packages/patches/net-tools-bitrot.patch			\
   gnu/packages/patches/netcdf-config-date.patch			\
+  gnu/packages/patches/nethack-correct-directories-and-permissions.patch \
   gnu/packages/patches/ngircd-handle-zombies.patch		\
   gnu/packages/patches/ngircd-no-dns-in-tests.patch		\
   gnu/packages/patches/ninja-tests.patch			\
diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index fc16862..43aa9e5 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -49,10 +49,12 @@
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages backup)
   #:use-module (gnu packages base)
+  #:use-module (gnu packages bison)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages audio)
   #:use-module (gnu packages avahi)
   #:use-module (gnu packages boost)
+  #:use-module (gnu packages flex)
   #:use-module (gnu packages fribidi)
   #:use-module (gnu packages game-development)
   #:use-module (gnu packages gettext)
@@ -2243,3 +2245,112 @@ Red Eclipse provides fast paced and accessible gameplay.")
                      license:cc-by-sa3.0
                      license:cc-by3.0
                      license:cc0)))))
+
+(define-public nethack
+  (package
+    (name "nethack")
+    (version "3.6.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://sourceforge/" name "/" name "-"
+                                  (string-join (string-split version #\.) "")
+                                  "-src.tgz"))
+              (sha256
+               (base32
+                "12mi5kgqw3q029y57pkg3gnp930p7yvlqi118xxdif2qhj6nkphs"))
+              (patches
+               (search-patches
+                "nethack-correct-directories-and-permissions.patch"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f ; no check target
+       #:make-flags '("CC=gcc" "LEX=flex" "YACC=bison -y")
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'configure
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((out (assoc-ref outputs "out")))
+               (substitute* "sys/unix/hints/linux"
+                 (("^PREFIX=.*$")
+                  (string-append "PREFIX=" out "\n"))
+                 (("^HACKDIR=.*$")
+                  (string-append "HACKDIR=" out "/var/hackdir\n"))
+                 (("^SHELLDIR=.*$")
+                  (string-append "SHELLDIR=" out "/var\n"))
+                 (("/bin/gzip") (which "gzip")))
+               (substitute* "sys/unix/setup.sh"
+                 (("/bin/sh") (which "bash"))))
+             (zero? (system* "sh" "sys/unix/setup.sh" "sys/unix/hints/linux"))))
+         (add-after 'install 'post-install
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out")))
+               (mkdir-p (string-append out "/var/nethack/save"))
+               (chdir (string-append out "/var/hackdir"))
+               (delete-file-recursively "save")
+
+               ; unnecessary script, the one wrapped below runs fine
+               (delete-file-recursively (string-append out "/games"))
+               (install-file "recover" (string-append out "/bin"))
+               (delete-file "recover")
+               (for-each (lambda (file)
+                           (install-file file
+                                         (string-append
+                                          out
+                                          "/var/nethack"))
+                           (delete-file file))
+                         '("logfile" "perm" "record" "xlogfile"))
+             #t)))
+         (add-after 'post-install 'wrap-program
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (nethack-user-dir "~/.nethack"))
+               (with-directory-excursion bin
+                 (call-with-output-file "nethack"
+                   (lambda (port)
+                     (format port "#!~a/bin/sh -e
+# Create NetHack directory in user's $HOME if it isn't there
+if [ ! -d ~a ]; then
+  mkdir -p ~a
+  cp -r ~a/* ~a
+  chmod -R +w ~a
+fi
+
+RUNDIR=$(mktemp -d)
+
+cleanup() {
+  rm -rf $RUNDIR
+}
+trap cleanup EXIT
+
+cd $RUNDIR
+for i in ~a/*; do
+  ln -s $i $(basename $i)
+done
+for i in ~a/*; do
+  ln -s $i $(basename $i)
+done
+./nethack~%"
+                             (assoc-ref inputs "bash") ;implicit input
+                             (string-append nethack-user-dir)
+                             (string-append nethack-user-dir)
+                             (string-append
+                              out "/var/nethack")
+                             (string-append nethack-user-dir)
+                             (string-append nethack-user-dir)
+                             (string-append nethack-user-dir)
+                             (string-append out "/var/hackdir")
+                             (string-append out))))
+                 (chmod "nethack" #o555)))
+             #t)))))
+    (native-inputs
+     `(("bison" ,bison)
+       ("flex" ,flex)))
+    (inputs `(("ncurses" ,ncurses)))
+    (home-page "http://nethack.org")
+    (synopsis "Single player dungeon exploration game")
+    (description
+     "Nethack is a roguelike game that emphasizes discovery of details in the
+dungeon.  The random number generator provides an unlimited number of
+variations of the dungeon.")
+    (license (license:fsf-free "http://nethack.org/common/license.html"))))
diff --git a/gnu/packages/patches/nethack-correct-directories-and-permissions.patch b/gnu/packages/patches/nethack-correct-directories-and-permissions.patch
new file mode 100644
index 0000000..9154712
--- /dev/null
+++ b/gnu/packages/patches/nethack-correct-directories-and-permissions.patch
@@ -0,0 +1,40 @@
+Patch by Kei Kebreau <kei@openmailbox.org>
+Keeping "#define CHDIR" makes NetHack unable to find its scoreboard record.
+The other two modifications enable building on Linux and building with the
+ncurses library, respectively.
+
+diff -r -u nethack-3.6.0.orig/include/config.h nethack-3.6.0/include/config.h
+--- nethack-3.6.0.orig/include/config.h	2016-05-27 17:20:03.062318307 -0400
++++ nethack-3.6.0/include/config.h	2016-05-31 16:48:04.283642766 -0400
+@@ -308,7 +308,6 @@
+ #define INSURANCE /* allow crashed game recovery */
+ 
+ #ifndef MAC
+-#define CHDIR /* delete if no chdir() available */
+ #endif
+ 
+ #ifdef CHDIR
+diff -r -u nethack-3.6.0.orig/include/unixconf.h nethack-3.6.0/include/unixconf.h
+--- nethack-3.6.0.orig/include/unixconf.h	2016-05-27 17:20:03.062318307 -0400
++++ nethack-3.6.0/include/unixconf.h	2016-05-30 20:33:52.132273630 -0400
+@@ -36,7 +36,7 @@
+ #define NETWORK        /* if running on a networked system */
+                        /* e.g. Suns sharing a playground through NFS */
+ /* #define SUNOS4 */   /* SunOS 4.x */
+-/* #define LINUX */    /* Another Unix clone */
++#define LINUX          /* Another Unix clone */
+ /* #define CYGWIN32 */ /* Unix on Win32 -- use with case sensitive defines */
+ /* #define GENIX */    /* Yet Another Unix Clone */
+ /* #define HISX */     /* Bull Unix for XPS Machines */
+diff -r -u nethack-3.6.0.orig/sys/unix/Makefile.src nethack-3.6.0/sys/unix/Makefile.src
+--- nethack-3.6.0.orig/sys/unix/Makefile.src	2016-05-27 17:20:03.082318966 -0400
++++ nethack-3.6.0/sys/unix/Makefile.src	2016-06-05 12:30:33.301505514 -0400
+@@ -238,7 +238,7 @@
+ # WINTTYLIB = -ltermcap
+ # WINTTYLIB = -lcurses
+ # WINTTYLIB = -lcurses16
+-# WINTTYLIB = -lncurses
++WINTTYLIB = -lncurses
+ #WINTTYLIB = -ltermlib
+ #
+ # libraries for X11
-- 
2.8.3


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-06 20:25   ` Kei Kebreau
@ 2016-06-07 17:20     ` Leo Famulari
  2016-06-08 12:59       ` Ludovic Courtès
  0 siblings, 1 reply; 10+ messages in thread
From: Leo Famulari @ 2016-06-07 17:20 UTC (permalink / raw)
  To: Kei Kebreau; +Cc: guix-devel

On Mon, Jun 06, 2016 at 04:25:41PM -0400, Kei Kebreau wrote:
> ludo@gnu.org (Ludovic Courtès) wrote:
> > > +         (add-after 'move-state-files 'wrap-program
> > 
> > Do we really need this wrapper?  Can’t we instead take it as a patch
> > from Debian or something?  I’m not a fan of inline Bash code, and not
> > very confident of scripts that do ‘rm -rf’.  :-)
> > 
> Unfortunately, Debian doesn't have any related patches because it's
> state files are writable in the equivalent of our store directories. It
> seems like the bash script will have to stay for the sake of
> functionality unless someone comes up with something cleaner, though I
> prefer to avoid them. Long ago, I lost a GNU/Linux installation to
> "rm -rf"...

If Nethack lacks the ability to configure the location of the state
files, there is still a string (or several) in the source code that
looks like '/usr/share/nethack'. I think we should change this string to
something more appropriate instead of wrapping Nethack.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-07 17:20     ` Leo Famulari
@ 2016-06-08 12:59       ` Ludovic Courtès
  2016-06-08 18:05         ` Kei Kebreau
  0 siblings, 1 reply; 10+ messages in thread
From: Ludovic Courtès @ 2016-06-08 12:59 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel

Leo Famulari <leo@famulari.name> skribis:

> On Mon, Jun 06, 2016 at 04:25:41PM -0400, Kei Kebreau wrote:
>> ludo@gnu.org (Ludovic Courtès) wrote:
>> > > +         (add-after 'move-state-files 'wrap-program
>> > 
>> > Do we really need this wrapper?  Can’t we instead take it as a patch
>> > from Debian or something?  I’m not a fan of inline Bash code, and not
>> > very confident of scripts that do ‘rm -rf’.  :-)
>> > 
>> Unfortunately, Debian doesn't have any related patches because it's
>> state files are writable in the equivalent of our store directories. It
>> seems like the bash script will have to stay for the sake of
>> functionality unless someone comes up with something cleaner, though I
>> prefer to avoid them. Long ago, I lost a GNU/Linux installation to
>> "rm -rf"...
>
> If Nethack lacks the ability to configure the location of the state
> files, there is still a string (or several) in the source code that
> looks like '/usr/share/nethack'. I think we should change this string to
> something more appropriate instead of wrapping Nethack.

Yeah, I would also prefer something along these lines.

What do you think, Kei?  Does that sound doable?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-08 12:59       ` Ludovic Courtès
@ 2016-06-08 18:05         ` Kei Kebreau
  2016-06-08 20:44           ` Leo Famulari
  0 siblings, 1 reply; 10+ messages in thread
From: Kei Kebreau @ 2016-06-08 18:05 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1581 bytes --]

On Wed, 08 Jun 2016 14:59:35 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

> Leo Famulari <leo@famulari.name> skribis:
> 
> > On Mon, Jun 06, 2016 at 04:25:41PM -0400, Kei Kebreau wrote:  
> >> ludo@gnu.org (Ludovic Courtès) wrote:  
> >> > > +         (add-after 'move-state-files 'wrap-program  
> >> > 
> >> > Do we really need this wrapper?  Can’t we instead take it as a
> >> > patch from Debian or something?  I’m not a fan of inline Bash
> >> > code, and not very confident of scripts that do ‘rm -rf’.  :-)
> >> >   
> >> Unfortunately, Debian doesn't have any related patches because it's
> >> state files are writable in the equivalent of our store
> >> directories. It seems like the bash script will have to stay for
> >> the sake of functionality unless someone comes up with something
> >> cleaner, though I prefer to avoid them. Long ago, I lost a
> >> GNU/Linux installation to "rm -rf"...  
> >
> > If Nethack lacks the ability to configure the location of the state
> > files, there is still a string (or several) in the source code that
> > looks like '/usr/share/nethack'. I think we should change this
> > string to something more appropriate instead of wrapping Nethack.  
> 
> Yeah, I would also prefer something along these lines.
> 
> What do you think, Kei?  Does that sound doable?
> 
> Thanks,
> Ludo’.

I'm not so sure. Is there a way that I can explicitly access the
home directory of the user that invokes guix? That is, something
clearer than "~/.nethack"?

-- 
Kei (GPG Key: 4096R/E6A5EE3C19467A0D)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-08 18:05         ` Kei Kebreau
@ 2016-06-08 20:44           ` Leo Famulari
  2016-06-09  1:17             ` Kei Kebreau
  0 siblings, 1 reply; 10+ messages in thread
From: Leo Famulari @ 2016-06-08 20:44 UTC (permalink / raw)
  To: Kei Kebreau; +Cc: guix-devel

On Wed, Jun 08, 2016 at 02:05:32PM -0400, Kei Kebreau wrote:
> I'm not so sure. Is there a way that I can explicitly access the
> home directory of the user that invokes guix? That is, something
> clearer than "~/.nethack"?

Do we have any package definitions that write to '/home/$USER'? I would
rather we didn't do that as a side effect of installing the package.

It's really the responsibility of the packaged software to set this up
when the user first runs it. If it can't, the user can copy the
"template" state files from '/gnu/store/...-nethack/whatever' into their
home directory.

Have you asked the NetHack maintainers for advice?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-08 20:44           ` Leo Famulari
@ 2016-06-09  1:17             ` Kei Kebreau
  2016-12-30 21:30               ` Chris Marusich
  0 siblings, 1 reply; 10+ messages in thread
From: Kei Kebreau @ 2016-06-09  1:17 UTC (permalink / raw)
  To: Leo Famulari; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1270 bytes --]

On Wed, 8 Jun 2016 16:44:36 -0400
Leo Famulari <leo@famulari.name> wrote:

> On Wed, Jun 08, 2016 at 02:05:32PM -0400, Kei Kebreau wrote:
> > I'm not so sure. Is there a way that I can explicitly access the
> > home directory of the user that invokes guix? That is, something
> > clearer than "~/.nethack"?  
> 
> Do we have any package definitions that write to '/home/$USER'? I
> would rather we didn't do that as a side effect of installing the
> package.
>

I haven't seen any packages definitions that do that in my casual
browsing the source tree. I wouldn't want to do that either, but it is
the only way I can come up with to get NetHack working while
minimally changing how it works. Doing more than this may require
patches in NetHack's C code, but I'm not familiar with the code base.

> It's really the responsibility of the packaged software to set this up
> when the user first runs it. If it can't, the user can copy the
> "template" state files from '/gnu/store/...-nethack/whatever' into
> their home directory.
>
> Have you asked the NetHack maintainers for advice?

I haven't asked NetHack maintainers for advice yet. It seems like that
would be the next logical step, though.

-- 
Kei (GPG Key: 4096R/E6A5EE3C19467A0D)

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-06-09  1:17             ` Kei Kebreau
@ 2016-12-30 21:30               ` Chris Marusich
  2016-12-30 21:47                 ` Kei Kebreau
  0 siblings, 1 reply; 10+ messages in thread
From: Chris Marusich @ 2016-12-30 21:30 UTC (permalink / raw)
  To: Kei Kebreau; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

Hi Kei,

I felt the need to play a game, so I was looking into packaging Nethack.
But I then found this email thread and saw that you already tried it!
Inspired by the RPG theme, I decided to perform thread necromancy! :-)

How did this pan out?  It looks like Nethack didn't wind up in the Guix
git repo.  Was there a blocking issue?  The plan to create a ~/.nethack
directory sounds like a good idea.

Kei Kebreau <kei@openmailbox.org> writes:

> I haven't asked NetHack maintainers for advice yet. It seems like that
> would be the next logical step, though.

Did you ever talk with them about the issues you found?

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] gnu: Add nethack.
  2016-12-30 21:30               ` Chris Marusich
@ 2016-12-30 21:47                 ` Kei Kebreau
  0 siblings, 0 replies; 10+ messages in thread
From: Kei Kebreau @ 2016-12-30 21:47 UTC (permalink / raw)
  To: Chris Marusich; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1326 bytes --]

Chris Marusich <cmmarusich@gmail.com> writes:

> Hi Kei,
>
> I felt the need to play a game, so I was looking into packaging Nethack.
> But I then found this email thread and saw that you already tried it!
> Inspired by the RPG theme, I decided to perform thread necromancy! :-)
>
> How did this pan out?  It looks like Nethack didn't wind up in the Guix
> git repo.  Was there a blocking issue?  The plan to create a ~/.nethack
> directory sounds like a good idea.
>

Creating the ~/.nethack directory does in fact work, but the last
NetHack patch in that thread messes with the user's home directory as
part of the installation process, which is forbidden for official Guix
packages. The correct fix for this would be to patch NetHack's source
code so that writing to files in the store (this is why I used the
~/.nethack directory workaround) would be unnecessary.

> Kei Kebreau <kei@openmailbox.org> writes:
>
>> I haven't asked NetHack maintainers for advice yet. It seems like that
>> would be the next logical step, though.
>
> Did you ever talk with them about the issues you found?

I emailed them but never received a response.

P.S. I've been pondering on the patch for a while now, and IIRC Chris
Webber had a WIP angband patch on the mailing list as well. Help with
either package would be well appreciated! :-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-12-30 21:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-31 21:56 [PATCH] gnu: Add nethack Kei Kebreau
2016-06-04 21:15 ` Ludovic Courtès
2016-06-06 20:25   ` Kei Kebreau
2016-06-07 17:20     ` Leo Famulari
2016-06-08 12:59       ` Ludovic Courtès
2016-06-08 18:05         ` Kei Kebreau
2016-06-08 20:44           ` Leo Famulari
2016-06-09  1:17             ` Kei Kebreau
2016-12-30 21:30               ` Chris Marusich
2016-12-30 21:47                 ` Kei Kebreau

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).