diff options
author | aszlig <aszlig@redmoonstudios.org> | 2016-02-08 22:15:55 +0100 |
---|---|---|
committer | aszlig <aszlig@redmoonstudios.org> | 2016-02-08 22:15:55 +0100 |
commit | 3c6c1392de4ee4a6c0bb13cb7908f9304d6dd053 (patch) | |
tree | 8eb7abf04eb250e5337c90acb69103adaeeef422 /pkgs/games/steam/starbound.nix | |
parent | 42c3024877bbdd127e7002e35f41cd87aaf792f7 (diff) | |
parent | 5570ec94ffe086f1ff47ad99606d39eb7b815dd1 (diff) |
Merge aszlig/nixgames into vuizvui
This is a subtree merge of the full nixgames repository including history. Right now it isn't linked to vuizvui at all but we're going to do that very soon. The reason why I'm merging both repositories together is that it's easier for me to manage updates and also facilitate contributions by people from the OpenLab. Another reason to merge it is that we can write more generic functions for building both, the games and the rest. Right now the licensing is still the Apache License version 2.0, but we're going to change it to the vuizvui license as well.
Diffstat (limited to 'pkgs/games/steam/starbound.nix')
-rw-r--r-- | pkgs/games/steam/starbound.nix | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/pkgs/games/steam/starbound.nix b/pkgs/games/steam/starbound.nix new file mode 100644 index 00000000..ba63fcfa --- /dev/null +++ b/pkgs/games/steam/starbound.nix @@ -0,0 +1,132 @@ +{ stdenv, fetchSteam, makeWrapper, SDL, mesa, flavor ? "stable" }: + +let + renameAttrs = f: let + rename = name: value: { + name = f name; + inherit value; + }; + in stdenv.lib.mapAttrs' rename; + + darwinize = renameAttrs (bin: "Starbound.app/Contents/MacOS/${bin}"); + winize = renameAttrs (bin: "${bin}.exe"); + + mkOsBinaryDeps = with stdenv.lib; + if stdenv.system == "x86_64-darwin" then darwinize + else if elem stdenv.system [ "i686-cygwin" "x86_64-cygwin" ] then winize + else id; + + binaryDeps = mkOsBinaryDeps { + starbound.deps = [ SDL mesa ]; + starbound_server.name = "starbound-server"; + asset_packer.name = "starbound-asset-packer"; + asset_unpacker.name = "starbound-asset-unpacker"; + dump_versioned_json.name = "starbound-dump-versioned-json"; + make_versioned_json.name = "starbound-make-versioned-json"; + planet_mapgen.name = "starbound-planet-mapgen"; + }; + + binpath = if stdenv.system == "x86_64-linux" then "linux64" + else if stdenv.system == "i686-linux" then "linux32" + else if stdenv.system == "x86_64-darwin" then "osx" + else if stdenv.system == "i686-cygwin" then "win32" + else if stdenv.system == "x86_64-cygwin" then "win64" + else throw "Unsupported system ${stdenv.system} for Starbound"; + + upstream = let + attrs = if flavor == "stable" then { + name = "starbound"; + appId = 211820; + depotId = 211821; + manifestId = 1842730272313189605; + sha256 = "0qppfn56c778wsg38hi6sxgi3rl9nv72h9rmmxybi1vzpf3p49py"; + } else if flavor == "unstable" then { + name = "starbound-unstable"; + appId = 367540; + depotId = 367541; + manifestId = 6970641909803280413; + sha256 = "0qppfn56c778wsg38hi6sxgi3rl9nv72h9rmmxybi1vzpf3p49py"; + } else throw "Unsupported flavor, use either `stable' or `unstable'."; + in fetchSteam (attrs // { + fileList = [ + "^(?:assets|tiled)/" + ( "^${binpath}(?:/Starbound\\.app/Contents/MacOS)?" + + "/(?:[a-zA-Z0-9_-]+(?:\\.exe)?|sbboot\\.config)$") + ]; + }); + +in stdenv.mkDerivation { + name = "${upstream.name}-20160208"; + + unpackPhase = ":"; + + configurePhase = '' + libexec="$out/libexec/starbound" + data="$out/share/starbound" + ''; + + inherit binpath upstream; + + buildInputs = [ makeWrapper ]; + + buildPhase = with stdenv.lib; '' + mkdir -p patched + sed -e 's,\.\./assets,'"$data/assets"',g' \ + -e 's,\.\./giraffe_storage,.,g' \ + "$upstream/$binpath/sbboot.config" > "patched/sbboot.config" + '' + concatStrings (mapAttrsToList (bin: attrs: '' + mkdir -p "patched/$(dirname "${bin}")" + cp -t "patched/$(dirname "${bin}")" "$upstream/$binpath/${bin}" + chmod +x "patched/$(basename "${bin}")" + patchelf \ + --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath "${stdenv.lib.makeLibraryPath (attrs.deps or [])}" \ + "patched/$(basename "${bin}")" + if ldd "patched/$(basename "${bin}")" | grep -F 'not found'; then + exit 1; + fi + '') binaryDeps); + + doCheck = true; + + checkPhase = '' + checkFailed= + for i in "$upstream/$binpath"/*; do + [ -f "$i" ] || continue + [ "$(basename "$i")" != launcher ] || continue + [ ! -e "patched/$(basename "$i")" ] || continue + + echo "Found missing binary $i from the upstream tree." + checkFailed=1 + done + [ -z "$checkFailed" ] + ''; + + installPhase = '' + mkdir -p "$out/bin" + ${stdenv.lib.concatStrings (stdenv.lib.mapAttrsToList (bin: attrs: '' + prog="$(basename "${bin}")" + install -vD "patched/$prog" "$libexec/$prog" + cat > "$out/bin/${attrs.name or "$prog"}" <<EOF + #!${stdenv.shell} -e + [ -n "\$XDG_DATA_HOME" ] || XDG_DATA_HOME="\$HOME/.local/share" + mkdir -p "\$XDG_DATA_HOME/starbound/mods" + ln -sf "$out/etc/sbboot.config" "\$XDG_DATA_HOME/starbound/sbboot.config" + cd "\$XDG_DATA_HOME/starbound" + exec "$libexec/$prog" "\$@" + EOF + chmod +x "$out/bin/${attrs.name or "$prog"}" + '') binaryDeps)} + + install -vD -m 644 patched/sbboot.config "$out/etc/sbboot.config" + + mkdir -p "$data" + for i in assets tiled; do + echo -n "Installing $i..." + cp -rt "$data" "$upstream/$i" + echo " done." + done + ''; + + dontStrip = true; +} |