From 309fcf6eeb7ee4cb703956418bf73aa8d69731c5 Mon Sep 17 00:00:00 2001 From: Atemu Date: Tue, 3 Sep 2024 01:22:40 +0200 Subject: [PATCH 1/2] steamtinkerlaunch: don't wrap in order to preserve $0 Fixes https://github.com/NixOS/nixpkgs/issues/295902 --- .../tools/games/steamtinkerlaunch/default.nix | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/pkgs/tools/games/steamtinkerlaunch/default.nix b/pkgs/tools/games/steamtinkerlaunch/default.nix index 42935ad6e393..bf414fb2b34b 100644 --- a/pkgs/tools/games/steamtinkerlaunch/default.nix +++ b/pkgs/tools/games/steamtinkerlaunch/default.nix @@ -3,7 +3,6 @@ , gawk , git , lib -, makeWrapper , procps , stdenvNoCC , unixtools @@ -12,6 +11,7 @@ , xdotool , xorg , yad +, writeShellApplication }: stdenvNoCC.mkDerivation { @@ -25,31 +25,39 @@ stdenvNoCC.mkDerivation { hash = "sha256-CGtSGAm+52t2zFsPJEsm76w+FEHhbOd9NYuerGa31tc="; }; - # hardcode PROGCMD because #150841 - postPatch = '' - substituteInPlace steamtinkerlaunch --replace 'PROGCMD="''${0##*/}"' 'PROGCMD="steamtinkerlaunch"' - ''; - - nativeBuildInputs = [ makeWrapper ]; - installFlags = [ "PREFIX=\${out}" ]; - postInstall = '' - wrapProgram $out/bin/steamtinkerlaunch --prefix PATH : ${lib.makeBinPath [ - bash - gawk - git - procps - unixtools.xxd - unzip - wget - xdotool - xorg.xprop - xorg.xrandr - xorg.xwininfo - yad - ]} - ''; + postInstall = + let + # We (ab)use writeShellApplication to produce a header for a shell script + # here in order to add the runtimePath to the original script. We cannot + # wrap here as that always corrupts $0 in bash scripts which STL uses to + # install its compat tool. + header = writeShellApplication { + runtimeInputs = [ + bash + gawk + git + procps + unixtools.xxd + unzip + wget + xdotool + xorg.xprop + xorg.xrandr + xorg.xwininfo + yad + ]; + name = "stl-head"; + text = ""; + bashOptions = [ ]; + }; + in + '' + cp $out/bin/steamtinkerlaunch $TMPDIR/steamtinkerlaunch + install ${lib.getExe header} -T $out/bin/steamtinkerlaunch + tail -n +2 $TMPDIR/steamtinkerlaunch >> $out/bin/steamtinkerlaunch + ''; meta = with lib; { description = "Linux wrapper tool for use with the Steam client for custom launch options and 3rd party programs"; From 1dc34aa94a169cdbde87396fd5ffadac19c5627d Mon Sep 17 00:00:00 2001 From: Atemu Date: Tue, 3 Sep 2024 03:03:28 +0200 Subject: [PATCH 2/2] steamtinkerlaunch: add steamcompattool output This makes it possible to integrate this into our steam derivation's extraCompatPackages --- .../tools/games/steamtinkerlaunch/default.nix | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkgs/tools/games/steamtinkerlaunch/default.nix b/pkgs/tools/games/steamtinkerlaunch/default.nix index bf414fb2b34b..0d7551ca30a2 100644 --- a/pkgs/tools/games/steamtinkerlaunch/default.nix +++ b/pkgs/tools/games/steamtinkerlaunch/default.nix @@ -25,8 +25,20 @@ stdenvNoCC.mkDerivation { hash = "sha256-CGtSGAm+52t2zFsPJEsm76w+FEHhbOd9NYuerGa31tc="; }; + outputs = [ "out" "steamcompattool" ]; + installFlags = [ "PREFIX=\${out}" ]; + nativeBuildInputs = let + # We need a `steam` command in order to install the compat tool + fakeSteam = writeShellApplication { + name = "steam"; + text = "exit 0"; + }; + in [ + fakeSteam + ]; + postInstall = let # We (ab)use writeShellApplication to produce a header for a shell script @@ -52,11 +64,31 @@ stdenvNoCC.mkDerivation { text = ""; bashOptions = [ ]; }; + fakeYad = writeShellApplication { + name = "yad"; + text = "echo ${yad.version} FAKE"; + }; in '' cp $out/bin/steamtinkerlaunch $TMPDIR/steamtinkerlaunch install ${lib.getExe header} -T $out/bin/steamtinkerlaunch tail -n +2 $TMPDIR/steamtinkerlaunch >> $out/bin/steamtinkerlaunch + + # Create a fake steam dir, it checks this and reads a few values + steamdir=$TMPDIR/.local/share/Steam/ + mkdir -p $steamdir/config/ + echo \"path\" \"$steamdir\" > $steamdir/config/config.vdf + mkdir $TMPDIR/.steam/ + ln -s $steamdir $TMPDIR/.steam/steam + + cp -a $out/bin/steamtinkerlaunch $TMPDIR/steamtinkerlaunch + # yad cannot print its version without a graphical session https://github.com/v1cont/yad/issues/277 + substituteInPlace $TMPDIR/steamtinkerlaunch --replace ${yad} ${fakeYad} + HOME=$TMPDIR $TMPDIR/steamtinkerlaunch compat add + + cp -a $steamdir/compatibilitytools.d/SteamTinkerLaunch $steamcompattool + # It creates this symlink but it points to $TMPDIR + ln -sfn $out/bin/steamtinkerlaunch $steamcompattool/ ''; meta = with lib; {