From 291e3b31567d9e28e6a29a17065861e479f896f9 Mon Sep 17 00:00:00 2001 From: aszlig Date: Sat, 12 Mar 2016 02:57:12 +0100 Subject: 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 --- pkgs/games/steam/starbound.nix | 86 ++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'pkgs/games/steam') 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" \ + < "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"}" <