about summary refs log tree commit diff
path: root/pkgs/games/steam
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-03-12 02:57:12 +0100
committeraszlig <aszlig@redmoonstudios.org>2016-03-15 04:55:48 +0100
commit291e3b31567d9e28e6a29a17065861e479f896f9 (patch)
treeecf21dd634e338125b2a83de8070fc65ca47f6ae /pkgs/games/steam
parent4c1051225a1bc99f3bab8512e26c221e860565f0 (diff)
games/starbound: Refactor to use JQ for bootconfig
While JQ is a beast of its own implementing its own turing complete
language, it *is* certainly useful and better than sed to replace path
values.

Now we have a new bootOverrides attribute set, which is converted into
JSON and then merged with the original sbboot.config by JQ at the time
we're setting up the XDG_DATA_HOME directory.

The reason this is necessary is that we can't use environment variables
directly in the boot configuration of Starbound, so we need to write the
boot configuration at initialization time with the absolute paths to
XDG_DATA_HOME.

Another change here is that we now reference the upstream store path
directly instead of copying over almost everything to our build result.

This has the advantage that we have fewer duplication and thus fewer
disk I/O while building.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/games/steam')
-rw-r--r--pkgs/games/steam/starbound.nix86
1 files changed, 50 insertions, 36 deletions
diff --git a/pkgs/games/steam/starbound.nix b/pkgs/games/steam/starbound.nix
index 0dab7cf2..17ba7ea7 100644
--- a/pkgs/games/steam/starbound.nix
+++ b/pkgs/games/steam/starbound.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchSteam, makeWrapper, SDL, mesa, flavor ? "stable" }:
+{ stdenv, fetchSteam, writeText, SDL, mesa, jq, flavor ? "stable" }:
 
 let
   renameAttrs = f: let
@@ -58,27 +58,61 @@ let
     ];
   };
 
+  bootOverrides = {
+    storageDirectory = "$XDG_DATA_HOME/starbound";
+    modSource = "$XDG_DATA_HOME/starbound/mods";
+    assetSources = [
+      "${upstream}/assets/packed.pak"
+      "${upstream}/assets/user"
+    ];
+  };
+
+  mkProg = bin: attrs: let
+    basename = builtins.baseNameOf bin;
+
+    hasBootconfigArg = attrs.hasBootconfigArg or false;
+
+    bootconfigArgs = with stdenv.lib; let
+      bootconfig = "$XDG_DATA_HOME/starbound/sbboot.config";
+      logfile = "$XDG_DATA_HOME/starbound/starbound.log";
+      args = " -bootconfig \"${bootconfig}\" -logfile \"${logfile}\"";
+    in optionalString hasBootconfigArg args;
+
+    wrapper = writeText "starbound-wrapper.sh" ''
+      #!${stdenv.shell} -e
+      [ -n "$XDG_DATA_HOME" ] || XDG_DATA_HOME="$HOME/.local/share"
+
+      mkdir -p "${bootOverrides.storageDirectory}" \
+               "${bootOverrides.modSource}"
+
+      "${jq}/bin/jq" -s '.[0] * .[1]' \
+        <(sed -e 's,//.*,,' "${upstream}/${binpath}/sbboot.config") \
+        - > "$XDG_DATA_HOME/starbound/sbboot.config" \
+      <<BOOTCONFIG_OVERRIDES
+      ${builtins.toJSON bootOverrides}
+      BOOTCONFIG_OVERRIDES
+
+      ${stdenv.lib.optionalString hasBootconfigArg ''
+        cd "$XDG_DATA_HOME/starbound"
+      ''}
+      exec "@out@/libexec/starbound/${basename}"${bootconfigArgs} "$@"
+    '';
+
+  in ''
+    install -vD "patched/${basename}" "$out/libexec/starbound/${basename}"
+    substituteAll "${wrapper}" "$out/bin/${attrs.name or basename}"
+    chmod +x "$out/bin/${attrs.name or basename}"
+  '';
+
 in stdenv.mkDerivation {
   name = "${upstreamInfo.name}-${upstreamInfo.version}";
   inherit (upstreamInfo) version;
 
   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: ''
+  buildPhase = with stdenv.lib; concatStrings (mapAttrsToList (bin: attrs: ''
     mkdir -p "patched/$(dirname "${bin}")"
     cp -t "patched/$(dirname "${bin}")" "$upstream/$binpath/${bin}"
     chmod +x "patched/$(basename "${bin}")"
@@ -97,6 +131,7 @@ in stdenv.mkDerivation {
     checkFailed=
     for i in "$upstream/$binpath"/*; do
       [ -f "$i" ] || continue
+      [ "$(basename "$i")" != sbboot.config ] || continue
       [ "$(basename "$i")" != launcher ] || continue
       [ ! -e "patched/$(basename "$i")" ] || continue
 
@@ -108,28 +143,7 @@ in stdenv.mkDerivation {
 
   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
+    ${stdenv.lib.concatStrings (stdenv.lib.mapAttrsToList mkProg binaryDeps)}
   '';
 
   dontStrip = true;