From cdd0ac7e5477602289ff8cee94930065e7bc570d Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 5 Jul 2018 17:21:24 -0400 Subject: [PATCH] dwarf-fortress: support older versions as well game.json now contains a dictionary of old game hashes. I have added them for the last 3 releases. - add script to generate hashes Makes it much easier to update game.json file. - add updateScript meta This adds some info on the ./update.sh updateScript now available. - cleanup updateScript - Add some more systems - Correctly detect source extensions (.zip or .tar.bz2) - Proper bash quoting - fix update.sh - correctly detect latest df version - append to game.json instead of overwriting it - update hashes for 44.12 --- pkgs/games/dwarf-fortress/default.nix | 4 +- pkgs/games/dwarf-fortress/game.json | 86 +++++++++++++++++++++++++++ pkgs/games/dwarf-fortress/game.nix | 58 +++++++++++------- pkgs/games/dwarf-fortress/update.sh | 42 +++++++++++++ 4 files changed, 166 insertions(+), 24 deletions(-) create mode 100644 pkgs/games/dwarf-fortress/game.json create mode 100755 pkgs/games/dwarf-fortress/update.sh diff --git a/pkgs/games/dwarf-fortress/default.nix b/pkgs/games/dwarf-fortress/default.nix index b959ea3eda7..480b36f3459 100644 --- a/pkgs/games/dwarf-fortress/default.nix +++ b/pkgs/games/dwarf-fortress/default.nix @@ -4,7 +4,9 @@ let callPackage = pkgs.newScope self; self = rec { - dwarf-fortress-original = callPackage ./game.nix { }; + dwarf-fortress-original = callPackage ./game.nix { + dfVersion = "0.44.11"; + }; dfhack = callPackage ./dfhack { inherit (pkgs.perlPackages) XMLLibXML XMLLibXSLT; diff --git a/pkgs/games/dwarf-fortress/game.json b/pkgs/games/dwarf-fortress/game.json new file mode 100644 index 00000000000..05fb0cf5080 --- /dev/null +++ b/pkgs/games/dwarf-fortress/game.json @@ -0,0 +1,86 @@ +{ + "0.43.05": { + "linux": "1r0b96yrdf24m9476k5x7rmp3faxr0kfwwdf35agpvlb1qbi6v45", + "linux32": "16l1lydpkbnl3zhz4i2snmjk7pps8vmw3zv0bjgr8dncbsrycd03", + "osx": "1j2zdkjnmxy8yn599pm0qmbi4zjp1m8h4ggqjxhyzp135h0lqqf9", + "osx32": "09ym4mflp5z78pk5mvj7b44xihnsvrxmh0b5kix6h1m6z3cc90l4", + "win": "0m337wh4c47ij1f3zrimvy7baff7nzrmgjbmrwdy89d0z90xpnx8", + "win_s": "0bjk5m1qkn3ldhqiwbq24y2m9fz9r574d54ngdb8b4ri2xfl1fbp", + "win32": "162rl9ygpj66pis87bqc5bwc0mk75hxv6ianhn87pbl4rh7g8ax8", + "win32_s": "0gv1jyw5fdskjjs27pr41grbmkk7ipqn0ry615f5g79k3mhl200i", + "legacy": "09lvbmg1gq257qchlbmq7hxc5nl9r39jpf73zhmwb5xfbpprn0zs", + "legacy_s": "023a5b27fm65w7gmzjssyyci70fdjk2zbv965y4n0f23kc4rj9gl", + "legacy32": "1m75arxj1q82l2dkk8qcargm3xczxlqi8krwvg3iimddky34gipq", + "legacy32_s": "1hgzsk66isfr5vcraxwgl7cvycl14kwf8w9kzxr8jyp5z7k24q29" + }, + "0.44.05": { + "linux": "18bjyhjp5458bfbizm8vq4s00pqpfs097qp6pv76m84kgbc4ghg3", + "linux32": "1b9i4kf4c8s6bhqwn8jx100mg7fqp8nmswrai5w8dsma01py4amr", + "osx": "1ssc8vq3ad38x9c04j8gg96kxv0g2npi3jwcg40676byx5nrx7b6", + "osx32": "12i7x8idcbvp5h62jyc7b7j98jf4lrisnwglvnrms6jclj0b3g0q", + "win": "1kaifarjx0akg7s5a2ngfw0vm0vyr4jnax5rrbv96dliqn5knddz", + "win_s": "1a1xikrjdv4b0yfgnp5s8d6xn0njylynsqd8zixdc01vccl5kqm6", + "win32": "1j3cq0h7jdvxbsbpfxa7bli45smvy9m4fji0j6849kj7x0vcpwq4", + "win32_s": "10cw1n48ffkrv9ms07ka5b5370d9k2fm051cnnq03lkcvlwrq145", + "legacy": "0y7xpgmwn4nshhc7apyf8mj5ycl0q5vckdaviwzz6w1x31s3dp6n", + "legacy_s": "0j8rbw9ww1avmh8zhyzljjj6in87q4qffpffdl394fsi74n8px0d", + "legacy32": "0d3l4jvx53a01fjf1lf20ar9lfyykfhk05dlrfwz3w4k7vj4vvlf", + "legacy32_s": "1c5x9x44bblz7anhmk4y9a7p1b39b9k7gzvj4pi55jzfq0k60kl7" + }, + "0.44.09": { + "linux": "1haikynkg1pqyrzzqk1qxm19p36ww58qp8brh3fjxssp4x71rcdy", + "linux32": "0lmbrdf7wjdwj5yx0khnq871yxvhfwqxjjyfkqcdy5ik18lvlkj8", + "osx": "01dss8g9lmi8majp6lxcfw166ydz4himkz6am5pi29gixaf4vfqs", + "osx32": "1iwlvmz1ir9k0kzn6726frmkznvsg9a99bbqnxvwcnq3nnnjxw3s", + "win": "08g5irgp59dfjgj3jxc8ixwzgnz2wghcl8cg1b1g4088dsf2x3x8", + "win_s": "1xyb4msn9wfrh7x136r8xn3sjz6z8c4zksbzifa0z0bpa3pdviap", + "win32": "0m8bs2mnyi1r4x84fwnfgd1ijdcf08xsq5zy84476svci932g5kz", + "win32_s": "0pl319qmyy96ibzlgj4wfj19dv1wzyg8ig6q11l4c7rivzc9286i", + "legacy": "0l8nrvppfzazhjsfkd5nd0bxnc6ljk8fs6yg8qh69g7q7zvzgnd3", + "legacy_s": "1c49z539a31czzq0rnhg6yrv1zbaja35sd0ssr4k7lsghjv84k1z", + "legacy32": "155xg6dpb8frlw7d9h7m1y0spw55wl4nkn7zrm70bpyp39pydlqp", + "legacy32_s": "05qkzjfx1ybrv96wya1dirdfxdkhj6a440sjpzwbqpkqgr8z57a3" + }, + "0.44.10": { + "linux": "1cqm43hn3ar9d8a7y7dwq48ajp72cirn1gclh8r2fykkypprxmp2", + "linux32": "0gdb6sq8725nwdisxwha8f5b6arq570s73aj4gdrh611gxh13r6n", + "osx": "1wpa45d81q8f5mhqmaxvdkz93k6cm3pg7vpsqjjjsp5s961gd74g", + "osx32": "0rsy1n19n12gh8rddgi3db32in488f2nizq8kw25hga03hsh4r6x", + "win": "04i0ka12hmn3chsyfmk2pbknr1pdf3p8yaz7kv82ri4g6dvsjfv6", + "win_s": "01m6nqcrz4rhdc8wb31azj3vmjid8bdpqaf9wkz4g4vvjyy7xiyz", + "win32": "1nymin8wbzbh8gm2702dy7h5spdijdxnysdz71ldyl0xx4vw68d9", + "win32_s": "1skz0jpfm6j9bins04kn96f3v3k0kvjqlh25x3129r3hh8xacnd3", + "legacy": "0s84vpfr2b5y1kda9allqjrpkaxw15mkblk9dq08syhsj19vspa7", + "legacy_s": "18b7ikp7xy2y071h3ydfh5mq9hw9y303rdqyikvra5ji3n5p96cm", + "legacy32": "1yh2fl3qwpy6wrxavhn75grbjygymnfh746hxbmc60la7y5flrpy", + "legacy32_s": "0j65w2hxgpccg9qsaz14r82qvnvfd0pbl2gyx9fv8d77kxhkc4pw" + }, + "0.44.11": { + "linux": "1qizfkxl2k6pn70is4vz94q4k55bc3pm13b2r6yqi6lw1cnna4sf", + "linux32": "11m39lfyrsxlw1g7f269q7fzwichg06l21fxhqzgvlvmzmxsf8q5", + "osx": "073hmcj7bm323m3xqi42605rkvmgmv83bnxz1byymgs8aqyfykkx", + "osx32": "0w5avnj86wprk8q0rb5qm9kxbigzk6dk0akqbw4m76jgg2jdmir7", + "win": "1yxyv1sycn5jc3g1y02d82154xydg3kbghis7l3xi28n3bh8387b", + "win_s": "1xzwl6c362wqgps911y9q8vndp8zyd20fc2p7pkzzmw2hrgfqi6q", + "win32": "16x2rg3gm3lh2akg7n057kkxxigb2ljz0nk685lmn4j0adq8l31p", + "win32_s": "1a2y220111d94mzj5y3jwpy062k8fw25akyp7yn3fwa17vwvn8zq", + "legacy": "0gfjmsfqj21hs4d1hm7fvppbdjspc4r2qnnp6mwcbgh67i5p5rdb", + "legacy_s": "1wr4hpzmhgl8haric3jpfd3kwqv1fi4vkb1gvaax5f7kplvfqfac", + "legacy32": "1cpzckwvqkxqn0c498mmh4papsjdi3mcvcp2vzlvj46kvdl3n0f0", + "legacy32_s": "024vzwfcrx7ms4dip0ccwd0vizzck2pwz2ryyvlz4rpjzhswj5gi" + }, + "0.44.12": { + "win32": "0bxrc7zj4vgcgdwc130g6f5jnp13vgx9a2kn2l1jcc958x8a367g", + "linux32": "0fmr8diskmbh12s0bpfn5gky9lmrc7xxj6va5adjm6ahxv9jwr06", + "osx": "1md6r1pimmlhcn5gjqzg0ygbdwc2v125sfjy0f6gbfbykwcm7391", + "osx32": "1dbg7pavxw20r8iqc566fn558avgj5glsycvi6ggbvsh0rpw6n5v", + "win": "0zb5ximqi5j7vyvgjzfz7ycadh5sgb7jlyaa68x0sjlbybdr1min", + "win_s": "1ncf5zr1fggr5knf30l0wh7spp376v1jcc6m9c86zim8azcfx0y7", + "linux": "0ydr5lnysy45nsznqp5r2pysdqn3f0xkrkh9v9l1md111mriabas", + "win32_s": "1mxbjkikf010skrpng51r86jmv4nal51j5n1y9kyhv344bq6chr9", + "legacy": "11a212ynhx18p3k8hvdjx199din14wggxiwz191b4309fznzpprz", + "legacy_s": "05madj529y18ndxrih96mivbzng1vz2zbzicrcnj58i2084zm23f", + "legacy32": "0rapcydiic2nq6idjf7fg53xsxk8dxzyi1vflpz554ghdrnsmwjv", + "legacy32_s": "16fgbd3lx4r270dxqj6gr1g1iqjj8cv389h2hw1l646xx28g8d2m" + } +} diff --git a/pkgs/games/dwarf-fortress/game.nix b/pkgs/games/dwarf-fortress/game.nix index 97a94c940cd..d1264cefe8c 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 ]; }; } diff --git a/pkgs/games/dwarf-fortress/update.sh b/pkgs/games/dwarf-fortress/update.sh new file mode 100755 index 00000000000..3db68122d35 --- /dev/null +++ b/pkgs/games/dwarf-fortress/update.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p jq nix coreutils curl + +# systems to generate hashes for +systems='linux linux32 osx osx32 + win win_s win32 win32_s + legacy legacy_s legacy32 legacy32_s' + +if [ $# -eq 0 ]; then + versions="$(curl http://www.bay12games.com/dwarves/ \ + | grep 'DOWNLOAD DWARF FORTRESS' \ + | sed 's/.*DOWNLOAD DWARF FORTRESS \([0-9.]*\) .*/\1/')" +else + versions="$@" +fi + +tmp1="$(mktemp)" +tmp2="$(mktemp)" +for version in $versions; do + for system in $systems; do + echo -n $version,$system, + ver=$(echo $version | sed -e s,^0\.,, | tr . _) + if [[ "$system" = *win* ]] || [[ "$system" = *legacy* ]]; then + ext=zip + else + ext=tar.bz2 + fi + nix-prefetch-url \ + http://www.bay12games.com/dwarves/df_${ver}_${system}.${ext} + done +done | jq --slurp --raw-input \ + 'split("\n") | .[:-1] | map(split(",")) | + map({ "version": .[0], "platform": .[1], "sha256": .[2] }) | + group_by(.version) | + map(map({"version": .version, (.platform): .sha256}) | add | + {(.version): .} | map_values(del(.version))) | add' \ + > "$tmp1" + +# Append $tmp1 to game.json. There should be a better way to handle +# this but all other attempts failed for me. +jq -M --argfile a "$tmp1" '. + $a' < "$(dirname "$0")/game.json" > "$tmp2" +cat "$tmp2" > "$(dirname "$0")/game.json"