From 19494f5bed5d6d71373ae15b60a3b8a86a42e3cf Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:10:05 -0400 Subject: [PATCH 1/4] jovian-support-scripts: Init with format scripts The support scripts are intended to replace vendor scripts for the little details we can't do the same way. We're adding the pair of scripts required to format external devices. Note that the scripts end-up relying on the steamos-manager service, which in turn already knows how to launch the hw-support scripts. How convenient. --- overlay.nix | 1 + pkgs/jovian-support-scripts/default.nix | 49 ++++++++++ .../steamos-format-device | 89 +++++++++++++++++++ .../steamos-format-sdcard | 10 +++ 4 files changed, 149 insertions(+) create mode 100644 pkgs/jovian-support-scripts/default.nix create mode 100755 pkgs/jovian-support-scripts/steamos-format-device create mode 100755 pkgs/jovian-support-scripts/steamos-format-sdcard diff --git a/overlay.nix b/overlay.nix index 42764be8..abaaa2f5 100644 --- a/overlay.nix +++ b/overlay.nix @@ -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 { }; diff --git a/pkgs/jovian-support-scripts/default.nix b/pkgs/jovian-support-scripts/default.nix new file mode 100644 index 00000000..ba602429 --- /dev/null +++ b/pkgs/jovian-support-scripts/default.nix @@ -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; + }; +} diff --git a/pkgs/jovian-support-scripts/steamos-format-device b/pkgs/jovian-support-scripts/steamos-format-device new file mode 100755 index 00000000..2a146a0c --- /dev/null +++ b/pkgs/jovian-support-scripts/steamos-format-device @@ -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" diff --git a/pkgs/jovian-support-scripts/steamos-format-sdcard b/pkgs/jovian-support-scripts/steamos-format-sdcard new file mode 100755 index 00000000..15d095d2 --- /dev/null +++ b/pkgs/jovian-support-scripts/steamos-format-sdcard @@ -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 "$@" From bd74e860df3b3917cae90e712c49abd6426bb524 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:14:34 -0400 Subject: [PATCH 2/4] steam-jupiter: Add support scripts to FHS env --- pkgs/steam-jupiter/fhsenv.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/steam-jupiter/fhsenv.nix b/pkgs/steam-jupiter/fhsenv.nix index 77d4cbe6..9d255ffc 100644 --- a/pkgs/steam-jupiter/fhsenv.nix +++ b/pkgs/steam-jupiter/fhsenv.nix @@ -4,6 +4,7 @@ { writeShellScriptBin , dmidecode , jovian-stubs +, jovian-support-scripts , steam-fhsenv # , steamos-polkit-helpers , ... @@ -16,6 +17,7 @@ let "writeShellScriptBin" "dmidecode" "jovian-stubs" + "jovian-support-scripts" "steam-fhsenv" "steamos-polkit-helpers" ]; @@ -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) From 8513672b0c203cf377e932db309037f333f8e890 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:15:07 -0400 Subject: [PATCH 3/4] steam: Ensure our support scripts override vendor stubs --- modules/steam/steam.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/steam/steam.nix b/modules/steam/steam.nix index b801c0c5..064460e2 100644 --- a/modules/steam/steam.nix +++ b/modules/steam/steam.nix @@ -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 ]; From 96ef1950d61291256c57add4e7a673de8600221e Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:12:16 -0400 Subject: [PATCH 4/4] steam: Add drive adoption support This is a bit of a misnomer. It also adds "better" formatting support. --- modules/steam/steam.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/steam/steam.nix b/modules/steam/steam.nix index 064460e2..6cda1a93 100644 --- a/modules/steam/steam.nix +++ b/modules/steam/steam.nix @@ -114,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"; }; }