From 633e7e8021e82dc831869071489412a8a2e50909 Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 13 Sep 2017 06:40:44 +0200 Subject: pkgs/build-game: Try to evade tarbombs A lot of games (especially Unity games) come as a tarbomb, so in order to avoid having those files all over the place we now create an additional directory before unpack and set the sourceRoot to that if it's a tarbomb and if that's not the case set it to the single file within that directory. Signed-off-by: aszlig --- pkgs/games/build-support/build-game.nix | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'pkgs/games/build-support') diff --git a/pkgs/games/build-support/build-game.nix b/pkgs/games/build-support/build-game.nix index 46ed83df..5117b330 100644 --- a/pkgs/games/build-support/build-game.nix +++ b/pkgs/games/build-support/build-game.nix @@ -4,6 +4,8 @@ assert withPulseAudio -> libpulseaudio != null; { buildInputs ? [] , nativeBuildInputs ? [] +, preUnpack ? "" +, setSourceRoot ? "" , installCheckPhase ? "" , runtimeDependencies ? [] , ... @@ -16,6 +18,23 @@ stdenv.mkDerivation ({ file ./setup-hooks/auto-patchelf.sh ] ++ nativeBuildInputs; + preUnpack = preUnpack + '' + mkdir "$name" + pushd "$name" &> /dev/null + ''; + + # Try to evade tarbombs + setSourceRoot = '' + popd &> /dev/null + '' + lib.optionalString (setSourceRoot == "") '' + unpackedFiles="$(find "$name" -mindepth 1 -maxdepth 1 -print)" + if [ $(echo "$unpackedFiles" | wc -l) -gt 1 ]; then + sourceRoot="$name" + else + sourceRoot="$name/''${unpackedFiles##*/}" + fi + ''; + runtimeDependencies = let deps = lib.optional withPulseAudio libpulseaudio ++ runtimeDependencies; in map (dep: dep.lib or dep) deps; @@ -45,5 +64,6 @@ stdenv.mkDerivation ({ dontStrip = true; dontPatchELF = true; } // removeAttrs attrs [ - "buildInputs" "nativeBuildInputs" "installCheckPhase" "runtimeDependencies" + "buildInputs" "nativeBuildInputs" "preUnpack" "setSourceRoot" + "installCheckPhase" "runtimeDependencies" ]) -- cgit 1.4.1