Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for formatting from the Deck UI #418

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions modules/steam/steam.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ in
hardware.pulseaudio.support32Bit = true;
hardware.steam-hardware.enable = mkDefault true;

environment.systemPackages = [ pkgs.gamescope-session pkgs.steamos-polkit-helpers pkgs.steamos-manager ];
environment.systemPackages = [
pkgs.gamescope-session
pkgs.steamos-polkit-helpers
pkgs.steamos-manager
pkgs.jovian-support-scripts
];

systemd.packages = [ pkgs.gamescope-session pkgs.steamos-manager ];

Expand Down Expand Up @@ -109,9 +114,7 @@ in
'';

jovian.steam.environment = {
# We don't support adopting a drive, yet.
STEAM_ALLOW_DRIVE_ADOPT = mkDefault "0";
# Ejecting doesn't work, either.
STEAM_ALLOW_DRIVE_ADOPT = mkDefault "1";
STEAM_ALLOW_DRIVE_UNMOUNT = mkDefault "1";
};
}
Expand Down
1 change: 1 addition & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ rec {
jovian-stubs = final.callPackage ./pkgs/jovian-stubs { };
jovian-greeter = final.callPackage ./pkgs/jovian-greeter { };
jovian-steam-protocol-handler = final.callPackage ./pkgs/jovian-steam-protocol-handler { };
jovian-support-scripts = final.callPackage ./pkgs/jovian-support-scripts { };

jovian-documentation = final.callPackage ./support/docs {
pagefind = final.callPackage ./pkgs/pagefind { };
Expand Down
49 changes: 49 additions & 0 deletions pkgs/jovian-support-scripts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{ stdenv
, resholve

, bash
, jq
, systemd
, util-linux
}:

let
solution = {
scripts = [ "bin/steamos-polkit-helpers/*" ];
interpreter = "${bash}/bin/bash";
inputs = [
jq
systemd
util-linux
];
keep = {
"${placeholder "out"}/bin/steamos-polkit-helpers/steamos-format-device" = true;
};
};
in
stdenv.mkDerivation {
name = "jovian-support-scripts";

buildCommand = ''
install -D -m 755 ${./steamos-format-sdcard} $out/bin/steamos-format-sdcard
install -D -m 755 ${./steamos-format-device} $out/bin/steamos-format-device

substituteInPlace $out/bin/steamos-format-sdcard \
--replace-fail "/usr/bin/steamos-polkit-helpers/steamos-format-device" "$out/bin/steamos-polkit-helpers/steamos-format-device"
(
cd $out/bin

mkdir -v steamos-polkit-helpers
cd steamos-polkit-helpers
ln -v -t . ../steamos-format-*
)

${resholve.phraseSolution "steamos-format-sdcard" solution}
${resholve.phraseSolution "steamos-format-device" solution}
'';

meta = {
# Any script defined here should be prioritized over Steam's own.
priority = -10;
};
}
89 changes: 89 additions & 0 deletions pkgs/jovian-support-scripts/steamos-format-device
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash

set -eu

# [Jovian]
#
# Not a polkit helper anymore, this calls the steamos-manager system service
# to poke through the fhsenv used here.
#
# Note that this is uh... quite a hack, but uh... works?
#
# The TLDR is:
#
# - We poke the steamos-manager to run the dbus endpoint for formatting
# - We `tail` the journal for the output from the script
#
# And uh, this fulfills the requirements for Steam (stage=... flags).
#

cleanup() {
>/dev/null 2>&1 \
kill -9 % || :
}

trap cleanup EXIT SIGINT SIGTERM

_call() {
object="$1"; shift
interface="$1"; shift
busctl --timeout=99y --expect-reply=yes -j \
call \
com.steampowered.SteamOSManager1 \
"$object" \
com.steampowered.SteamOSManager1."${interface}" \
"$@" \
| jq -r .data[0]
}

# Only supported flags, from the DBUS interface shape (ssb)
# • --skip-validation|--force)
# • --device)
# • --label)

DEVICE=""
LABEL="STEAM-$RANDOM"
VALIDATE="true"

OPTS=$(getopt -l force,skip-validation,device:,label: -n steamos-format-device -- "" "$@")

eval set -- "$OPTS"

while true; do
case "$1" in
--force)
# yes, this is just like --skip-validate in the vendor script
VALIDATE="false"
shift
;;
--skip-validation)
# yes, this is just like --force in the vendor script
VALIDATE="false"
shift
;;
--label)
LABEL="$2";
shift 2
;;
--device)
DEVICE="$2"
shift 2
;;
--) shift; break ;;
esac
done

if [[ "$DEVICE" == "" ]]; then
>&2 printf "Error: --device flag mandatory\n"
exit 1
fi

journalctl --lines=0 --follow \
--output cat \
--unit steamos-manager.service \
SYSLOG_IDENTIFIER=steamos-format-device &

process=$(_call "/com/steampowered/SteamOSManager1" Manager FormatDevice ssb "$DEVICE" "$LABEL" "$VALIDATE")
res="$(_call "${process}" "SubProcess" Wait)"

exit "$res"
10 changes: 10 additions & 0 deletions pkgs/jovian-support-scripts/steamos-format-sdcard
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -eu

# [Jovian]
# Not a polkit helper anymore, this calls the `format-device` helper following
# the same semantics as `usr/lib/hwsupport/format-sdcard.sh`.

exec /usr/bin/steamos-polkit-helpers/steamos-format-device \
--device /dev/mmcblk0 "$@"
3 changes: 3 additions & 0 deletions pkgs/steam-jupiter/fhsenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ writeShellScriptBin
, dmidecode
, jovian-stubs
, jovian-support-scripts
, steam-fhsenv
# , steamos-polkit-helpers
, ...
Expand All @@ -16,6 +17,7 @@ let
"writeShellScriptBin"
"dmidecode"
"jovian-stubs"
"jovian-support-scripts"
"steam-fhsenv"
"steamos-polkit-helpers"
];
Expand Down Expand Up @@ -47,6 +49,7 @@ let
extraPkgs = pkgs: (if args ? extraPkgs then args.extraPkgs pkgs else []) ++ [
dmidecode
jovian-stubs
jovian-support-scripts
sessionSwitcher

# FIXME: figure out how to fix pkexec (needs SUID in fhsenv, see https://github.com/NixOS/nixpkgs/issues/69338)
Expand Down
Loading