summary refs log tree commit diff
path: root/pkgs/games/dwarf-fortress/game.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/games/dwarf-fortress/game.nix')
-rw-r--r--pkgs/games/dwarf-fortress/game.nix58
1 files changed, 35 insertions, 23 deletions
diff --git a/pkgs/games/dwarf-fortress/game.nix b/pkgs/games/dwarf-fortress/game.nix
index 97a94c940cd4..d1264cefe8cd 100644
--- a/pkgs/games/dwarf-fortress/game.nix
+++ b/pkgs/games/dwarf-fortress/game.nix
@@ -3,36 +3,44 @@
 
 # Our own "unfuck" libs for macOS
 , ncurses, fmodex, gcc
+
+, dfVersion
 }:
 
-with lib;
+with lib; with builtins;
 
 let
-  baseVersion = "44";
-  patchVersion = "11";
-  dfVersion = "0.${baseVersion}.${patchVersion}";
-
   libpath = makeLibraryPath [ stdenv.cc.cc stdenv.cc.libc dwarf-fortress-unfuck SDL ];
 
   homepage = http://www.bay12games.com/dwarves/;
 
+  # Map Dwarf Fortress platform names to Nixpkgs platform names.
   # Other srcs are avilable like 32-bit mac & win, but I have only
   # included the ones most likely to be needed by Nixpkgs users.
-  srcs = {
-    "x86_64-linux" = fetchurl {
-      url = "${homepage}df_${baseVersion}_${patchVersion}_linux.tar.bz2";
-      sha256 = "1qizfkxl2k6pn70is4vz94q4k55bc3pm13b2r6yqi6lw1cnna4sf";
-    };
-    "i686-linux" = fetchurl {
-      url = "${homepage}df_${baseVersion}_${patchVersion}_linux32.tar.bz2";
-      sha256 = "11m39lfyrsxlw1g7f269q7fzwichg06l21fxhqzgvlvmzmxsf8q5";
-    };
-    "x86_64-darwin" = fetchurl {
-      url = "${homepage}df_${baseVersion}_${patchVersion}_osx.tar.bz2";
-      sha256 = "073hmcj7bm323m3xqi42605rkvmgmv83bnxz1byymgs8aqyfykkx";
-    };
+  platforms = {
+    "x86_64-linux" = "linux";
+    "i686-linux" = "linux32";
+    "x86_64-darwin" = "osx";
+    "i686-darwin" = "osx32";
+    "x86_64-cygwin" = "win";
+    "i686-cygwin" = "win32";
   };
 
+  dfVersionTriple = splitString "." dfVersion;
+  baseVersion = elemAt dfVersionTriple 1;
+  patchVersion = elemAt dfVersionTriple 2;
+
+  games = fromJSON (readFile ./game.json);
+  game = if hasAttr dfVersion games
+         then getAttr dfVersion games
+         else throw "Unknown Dwarf Fortress version: ${dfVersion}";
+  dfPlatform = if hasAttr stdenv.system platforms
+               then getAttr stdenv.system platforms
+               else throw "Unsupported system: ${stdenv.system}";
+  sha256 = if hasAttr dfPlatform game
+           then getAttr dfPlatform game
+           else throw "Unsupported dfPlatform: ${dfPlatform}";
+
 in
 
 assert dwarf-fortress-unfuck != null ->
@@ -41,9 +49,10 @@ assert dwarf-fortress-unfuck != null ->
 stdenv.mkDerivation {
   name = "dwarf-fortress-original-${dfVersion}";
 
-  src = if builtins.hasAttr stdenv.system srcs
-        then builtins.getAttr stdenv.system srcs
-        else throw "Unsupported systems";
+  src = fetchurl {
+    url = "${homepage}df_${baseVersion}_${patchVersion}_${dfPlatform}.tar.bz2";
+    inherit sha256;
+  };
 
   installPhase = ''
     mkdir -p $out
@@ -81,13 +90,16 @@ stdenv.mkDerivation {
     md5sum $exe | awk '{ print $1 }' > $out/hash.md5
   '';
 
-  passthru = { inherit baseVersion patchVersion dfVersion; };
+  passthru = {
+    inherit baseVersion patchVersion dfVersion;
+    updateScript = ./update.sh;
+  };
 
   meta = {
     description = "A single-player fantasy game with a randomly generated adventure world";
     inherit homepage;
     license = licenses.unfreeRedistributable;
-    platforms = attrNames srcs;
+    platforms = attrNames platforms;
     maintainers = with maintainers; [ a1russell robbinch roconnor the-kenny abbradar numinit ];
   };
 }