summary refs log tree commit diff
path: root/pkgs/games/nethack
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2015-06-29 14:19:12 +0300
committerNikolay Amiantov <ab@fmap.me>2015-07-28 12:33:29 +0300
commit6e049800ed40d073785b01cc8ea2ffc8606afb3d (patch)
treee346a985530ce7a8d4a8dbc960d665a123f3bd6d /pkgs/games/nethack
parent99750d89dd962cc7011b02e487ed1a38c7842524 (diff)
downloadnixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.tar
nixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.tar.gz
nixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.tar.bz2
nixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.tar.lz
nixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.tar.xz
nixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.tar.zst
nixpkgs-6e049800ed40d073785b01cc8ea2ffc8606afb3d.zip
nethack: update, adopt
Diffstat (limited to 'pkgs/games/nethack')
-rw-r--r--pkgs/games/nethack/default.nix92
1 files changed, 55 insertions, 37 deletions
diff --git a/pkgs/games/nethack/default.nix b/pkgs/games/nethack/default.nix
index d817cf64323..e5057c27e99 100644
--- a/pkgs/games/nethack/default.nix
+++ b/pkgs/games/nethack/default.nix
@@ -1,57 +1,75 @@
-a :  
-let 
-  fetchurl = a.fetchurl;
-
-  version = a.lib.attrByPath ["version"] "3.4.3" a; 
-  buildInputs = with a; [
-    ncurses flex bison
-  ];
-in
-rec {
+{ stdenv, fetchurl, writeScript, ncurses, gzip, flex, bison }:
+
+stdenv.mkDerivation rec {
+  name = "nethack-3.4.3";
+
   src = fetchurl {
     url = "mirror://sourceforge/nethack/nethack-343-src.tgz";
     sha256 = "1r3ghqj82j0bar62z3b0lx9hhx33pj7p1ppxr2hg8bgfm79c6fdv";
   };
 
-  inherit buildInputs;
-  configureFlags = [];
+  buildInputs = [ ncurses ];
+
+  nativeBuildInputs = [ flex bison ];
 
-  /* doConfigure should be removed if not needed */
-  phaseNames = ["preBuild" "doMakeInstall" "postInstall"];
-     
-  preBuild = a.fullDepEntry (''
+  preBuild = ''
     ( cd sys/unix ; sh setup.sh )
-    sed -e 's@.*define HACKDIR.*@\#define HACKDIR "/tmp/nethack"@' -i include/config.h
+
     sed -e '/define COMPRESS/d' -i include/config.h
-    sed -e '1i\#define COMPRESS "/usr/local/bin/gzip"' -i include/config.h
+    sed -e '1i\#define COMPRESS "${gzip}/bin/gzip"' -i include/config.h
     sed -e '1i\#define COMPRESS_EXTENSION ".gz"' -i include/config.h
+    sed -e '/define CHDIR/d' -i include/config.h
 
     sed -e '/extern char [*]tparm/d' -i win/tty/*.c
+
     sed -e 's/-ltermlib/-lncurses/' -i src/Makefile
     sed -e 's/^YACC *=.*/YACC = bison -y/' -i util/Makefile
     sed -e 's/^LEX *=.*/LEX = flex/' -i util/Makefile
 
-    sed -e 's@GAMEDIR = @GAMEDIR = /tmp/nethack@' -i Makefile
     sed -re 's@^(CH...).*@\1 = true@' -i Makefile
-  '') ["minInit" "doUnpack"];
 
-  postInstall = a.fullDepEntry (''
+    sed -e '/^ *cd /d' -i sys/unix/nethack.sh
+  '';
+
+  postInstall = ''
+    for i in logfile perm record save; do
+      rm -rf $out/games/lib/nethackdir/$i
+    done
+
     mkdir -p $out/bin
-    ln -s $out/games/nethack $out/bin/nethack
-    sed -i $out/bin/nethack -e '5aNEWHACKDIR="$HOME/.nethack"'
-    sed -i $out/bin/nethack -e '6amkdir -p "$NEWHACKDIR/save"'
-    sed -i $out/bin/nethack -e '7afor i in $(find "$NEWHACKDIR" -type l); do if ! test -e $(readlink "$i"); then rm "$i"; fi; done;'
-    sed -i $out/bin/nethack -e '8aln -s "$HACKDIR"/* "$NEWHACKDIR" &>/dev/null'
-    sed -i $out/bin/nethack -e '9atest -L "$NEWHACKDIR/record" && rm "$NEWHACKDIR"/record'
-    sed -i $out/bin/nethack -e '10aexport HACKDIR="$NEWHACKDIR"'
-  '') ["minInit" "defEnsureDir"];
-
-  makeFlags = [
-      "PREFIX=$out"
-    ];
-
-  name = "nethack-" + version;
-  meta = {
-    description = "rogue-like game";
+    cat <<EOF >$out/bin/nethack
+      #! ${stdenv.shell} -e
+      if [ ! -d ~/.nethack ]; then
+        mkdir -p ~/.nethack/save
+        for i in logfile perm record; do
+          [ ! -e ~/.nethack/\$i ] && touch ~/.nethack/\$i
+        done
+      fi
+
+      cd ~/.nethack
+
+      cleanup() {
+        for i in $out/games/lib/nethackdir/*; do
+          rm -rf \$(basename \$i)
+        done
+      }
+      trap cleanup EXIT
+
+      for i in $out/games/lib/nethackdir/*; do
+        ln -s \$i \$(basename \$i)
+      done
+      $out/games/nethack
+    EOF
+    chmod +x $out/bin/nethack
+  '';
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "Rogue-like game";
+    homepage = "http://nethack.org/";
+    license = "nethack";
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ abbradar ];
   };
 }