From ca1ac336ea4c9a98a9068764ba2132b1fb307984 Mon Sep 17 00:00:00 2001 From: hot burger <33610620+hotburger@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:22:48 -0700 Subject: [PATCH 01/11] package udev rule --- pkgs/jupiter-hw-support/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/jupiter-hw-support/default.nix b/pkgs/jupiter-hw-support/default.nix index 17177e6d..f3f2e580 100644 --- a/pkgs/jupiter-hw-support/default.nix +++ b/pkgs/jupiter-hw-support/default.nix @@ -22,7 +22,7 @@ let src = callPackage ./src.nix { }; solution = { - scripts = [ "bin/*" "lib/hwsupport/*.sh" ]; + scripts = [ "bin/*" "lib/hwsupport/*.sh" "lib/hwsupport/common-functions" ]; interpreter = "${bash}/bin/bash"; inputs = [ coreutils @@ -90,6 +90,12 @@ stdenv.mkDerivation { substituteInPlace $out/lib/hwsupport/* \ --replace-warn ". /usr/lib/hwsupport" ". $out/lib/hwsupport" + mkdir -p $out/lib/udev/rules.d + + substitute usr/lib/udev/rules.d/99-steamos-automount.rules $out/lib/udev/rules.d/99-steamos-automount.rules \ + --replace-warn "/bin/systemd-run" "${systemd}/bin/systemd-run" \ + --replace-warn "/usr/lib/hwsupport" "$out/lib/hwsupport" + ${resholve.phraseSolution "jupiter-hw-support" solution} runHook postInstall From f9dbf9e9c4a3113bae54f0623d52af0190244d3b Mon Sep 17 00:00:00 2001 From: hot burger <33610620+hotburger@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:13:04 -0700 Subject: [PATCH 02/11] add automount option --- modules/devices/steamdeck/hw-support.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/devices/steamdeck/hw-support.nix b/modules/devices/steamdeck/hw-support.nix index 88ca3015..dcda6745 100644 --- a/modules/devices/steamdeck/hw-support.nix +++ b/modules/devices/steamdeck/hw-support.nix @@ -14,6 +14,14 @@ in { options = { jovian.devices.steamdeck = { + enableAutoMountUdevRules = mkOption { + default = cfg.enable; + defaultText = lib.literalExpression "config.jovian.devices.steamdeck.enable"; + type = types.bool; + description = '' + Whether to enable udev rules to automatically mount SD cards upon insertion. + ''; + }; enableDefaultCmdlineConfig = mkOption { default = cfg.enable; defaultText = lib.literalExpression "config.jovian.devices.steamdeck.enable"; @@ -34,6 +42,11 @@ in }; config = mkMerge [ + (mkIf (cfg.enableAutoMountUdevRules) { + services.udev.packages = [ + pkgs.jupiter-hw-support + ]; + }) (mkIf (cfg.enableDefaultStage1Modules) { boot.initrd.kernelModules = [ "hid-generic" From bed1c6fd1ca310e9f4ef49ab0d83c0ee74651be9 Mon Sep 17 00:00:00 2001 From: hot burger <33610620+hotburger@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:28:55 -0700 Subject: [PATCH 03/11] also package sdcard rescan rules --- pkgs/jupiter-hw-support/default.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/jupiter-hw-support/default.nix b/pkgs/jupiter-hw-support/default.nix index f3f2e580..10941194 100644 --- a/pkgs/jupiter-hw-support/default.nix +++ b/pkgs/jupiter-hw-support/default.nix @@ -91,10 +91,12 @@ stdenv.mkDerivation { --replace-warn ". /usr/lib/hwsupport" ". $out/lib/hwsupport" mkdir -p $out/lib/udev/rules.d + cp usr/lib/udev/rules.d/99-steamos-automount.rules $out/lib/udev/rules.d + cp usr/lib/udev/rules.d/99-sdcard-rescan.rules $out/lib/udev/rules.d - substitute usr/lib/udev/rules.d/99-steamos-automount.rules $out/lib/udev/rules.d/99-steamos-automount.rules \ - --replace-warn "/bin/systemd-run" "${systemd}/bin/systemd-run" \ - --replace-warn "/usr/lib/hwsupport" "$out/lib/hwsupport" + substituteInPlace $out/lib/udev/rules.d/*.rules \ + --replace-fail "/bin/systemd-run" "${systemd}/bin/systemd-run" \ + --replace-fail "/usr/lib/hwsupport" "$out/lib/hwsupport" ${resholve.phraseSolution "jupiter-hw-support" solution} From 02cd8a972b9341b76990e302fadd691b3ba49439 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sun, 29 Sep 2024 20:27:50 -0400 Subject: [PATCH 04/11] jupiter-hw-support: Isolate patching paths into a patch... ... the removed UID/GID work will be coming back in its own patch next up. --- ...jovian.patch => automount-fix-system-paths.patch} | 12 ------------ pkgs/jupiter-hw-support/src.nix | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) rename pkgs/jupiter-hw-support/{jovian.patch => automount-fix-system-paths.patch} (82%) diff --git a/pkgs/jupiter-hw-support/jovian.patch b/pkgs/jupiter-hw-support/automount-fix-system-paths.patch similarity index 82% rename from pkgs/jupiter-hw-support/jovian.patch rename to pkgs/jupiter-hw-support/automount-fix-system-paths.patch index 36e52083..02ccf731 100644 --- a/pkgs/jupiter-hw-support/jovian.patch +++ b/pkgs/jupiter-hw-support/automount-fix-system-paths.patch @@ -2,18 +2,6 @@ diff --git a/usr/lib/hwsupport/steamos-automount.sh b/usr/lib/hwsupport/steamos- index 386f4d8..cf79351 100755 --- a/usr/lib/hwsupport/steamos-automount.sh +++ b/usr/lib/hwsupport/steamos-automount.sh -@@ -22,8 +22,9 @@ fi - ACTION=$1 - DEVBASE=$2 - DEVICE="/dev/${DEVBASE}" --DECK_UID=$(id -u deck) --DECK_GID=$(id -g deck) -+# Jovian: hardcode these for now -+DECK_UID=1000 -+DECK_GID=100 - - send_steam_url() - { @@ -33,7 +34,7 @@ send_steam_url() if pgrep -x "steam" > /dev/null; then # TODO use -ifrunning and check return value - if there was a steam process and it returns -1, the message wasn't sent diff --git a/pkgs/jupiter-hw-support/src.nix b/pkgs/jupiter-hw-support/src.nix index 9d19f53b..891b017d 100644 --- a/pkgs/jupiter-hw-support/src.nix +++ b/pkgs/jupiter-hw-support/src.nix @@ -21,7 +21,7 @@ stdenv.mkDerivation rec { (substituteAll { handler = jovian-steam-protocol-handler; systemd = systemd; - src = ./jovian.patch; + src = ./automount-fix-system-paths.patch; }) # Fix controller updates with python-hid >= 1.0.6 ./hid-1.0.6.patch From 91f86ebad5bf829e391073f2a2a54d0f083ebadf Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:21:35 -0400 Subject: [PATCH 05/11] jupiter-hw-support: Bring back UID/GID fix, but also username --- ...tomounting-works-for-any-UID-1000-us.patch | 45 +++++++++++++++++++ pkgs/jupiter-hw-support/src.nix | 2 + 2 files changed, 47 insertions(+) create mode 100644 pkgs/jupiter-hw-support/0001-Jovian-Ensure-automounting-works-for-any-UID-1000-us.patch diff --git a/pkgs/jupiter-hw-support/0001-Jovian-Ensure-automounting-works-for-any-UID-1000-us.patch b/pkgs/jupiter-hw-support/0001-Jovian-Ensure-automounting-works-for-any-UID-1000-us.patch new file mode 100644 index 00000000..6a9cc0b3 --- /dev/null +++ b/pkgs/jupiter-hw-support/0001-Jovian-Ensure-automounting-works-for-any-UID-1000-us.patch @@ -0,0 +1,45 @@ +From 42798ed60fbc601cefab84fd1f2c8dab95906702 Mon Sep 17 00:00:00 2001 +From: Samuel Dionne-Riel +Date: Sun, 29 Sep 2024 02:52:26 -0400 +Subject: [PATCH] =?UTF-8?q?[Jovian]=C2=A0Ensure=20automounting=20works=20f?= + =?UTF-8?q?or=20any=20UID=201000=20username?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Samuel Dionne-Riel +--- + usr/lib/hwsupport/steamos-automount.sh | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/usr/lib/hwsupport/steamos-automount.sh b/usr/lib/hwsupport/steamos-automount.sh +index 386f4d8..8583ca7 100755 +--- a/usr/lib/hwsupport/steamos-automount.sh ++++ b/usr/lib/hwsupport/steamos-automount.sh +@@ -22,8 +22,12 @@ fi + ACTION=$1 + DEVBASE=$2 + DEVICE="/dev/${DEVBASE}" +-DECK_UID=$(id -u deck) +-DECK_GID=$(id -g deck) ++# Jovian Experiments assumptions: ++# - UID for Steam user is 1000 ++# - Username is unknown ++DECK_UID=1000 ++DECK_GID=$(id -g "$DECK_UID") ++DECK_USERNAME=$(id -nu "$DECK_UID") + + send_steam_url() + { +@@ -90,7 +94,7 @@ do_mount() + "block_devices/${DEVBASE}" \ + Filesystem Mount \ + 'a{sv}' 3 \ +- as-user s deck \ ++ as-user s "$DECK_USERNAME" \ + auth.no_user_interaction b true \ + options s "$OPTS") + +-- +2.46.0 + diff --git a/pkgs/jupiter-hw-support/src.nix b/pkgs/jupiter-hw-support/src.nix index 891b017d..61387797 100644 --- a/pkgs/jupiter-hw-support/src.nix +++ b/pkgs/jupiter-hw-support/src.nix @@ -25,6 +25,8 @@ stdenv.mkDerivation rec { }) # Fix controller updates with python-hid >= 1.0.6 ./hid-1.0.6.patch + # Remove `deck` username assumption + ./0001-Jovian-Ensure-automounting-works-for-any-UID-1000-us.patch ]; installPhase = '' From 81d4c94d55c243535f4c05881ccc7f79b8cfe7fa Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 30 Sep 2024 02:22:16 -0400 Subject: [PATCH 06/11] jupiter-hw-support: Two minor fixes for silly system configs --- ...rden-against-mountpoint-being-listed.patch | 30 ++++++++++++++++ ...unt-Harden-against-missing-run-media.patch | 36 +++++++++++++++++++ pkgs/jupiter-hw-support/src.nix | 3 ++ 3 files changed, 69 insertions(+) create mode 100644 pkgs/jupiter-hw-support/0001-format-device-Harden-against-mountpoint-being-listed.patch create mode 100644 pkgs/jupiter-hw-support/0001-steamos-automount-Harden-against-missing-run-media.patch diff --git a/pkgs/jupiter-hw-support/0001-format-device-Harden-against-mountpoint-being-listed.patch b/pkgs/jupiter-hw-support/0001-format-device-Harden-against-mountpoint-being-listed.patch new file mode 100644 index 00000000..1246ea02 --- /dev/null +++ b/pkgs/jupiter-hw-support/0001-format-device-Harden-against-mountpoint-being-listed.patch @@ -0,0 +1,30 @@ +From eee1d1e1f8e6d7a2246e3428d71522e02b04c5d7 Mon Sep 17 00:00:00 2001 +From: Samuel Dionne-Riel +Date: Sun, 29 Sep 2024 21:45:49 -0400 +Subject: [PATCH] format-device: Harden against mountpoint being listed more + than once + +This can happen with some combination of bind mounts magic, where the +mount point may appear at more than one location at a time. + +Signed-off-by: Samuel Dionne-Riel +--- + usr/lib/hwsupport/format-device.sh | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/usr/lib/hwsupport/format-device.sh b/usr/lib/hwsupport/format-device.sh +index 65d77f8..0400ae8 100755 +--- a/usr/lib/hwsupport/format-device.sh ++++ b/usr/lib/hwsupport/format-device.sh +@@ -77,6 +77,8 @@ fi + # If any partitions on the device are mounted, unmount them before continuing + # to prevent problems later + lsblk -n "$STORAGE_DEVICE" -o MOUNTPOINTS | awk NF | sort -u | while read m; do ++ # Check the mountpoint still exists, in case the mount point is reported more than once. ++ test -e "$m" || continue + if ! umount "$m"; then + echo "Failed to unmount filesystem: $m" + exit 32 # EPIPE +-- +2.46.0 + diff --git a/pkgs/jupiter-hw-support/0001-steamos-automount-Harden-against-missing-run-media.patch b/pkgs/jupiter-hw-support/0001-steamos-automount-Harden-against-missing-run-media.patch new file mode 100644 index 00000000..c20129bd --- /dev/null +++ b/pkgs/jupiter-hw-support/0001-steamos-automount-Harden-against-missing-run-media.patch @@ -0,0 +1,36 @@ +From 55674111fe7956adb41c2b8d0c6fbb3c3d6ca8bf Mon Sep 17 00:00:00 2001 +From: Samuel Dionne-Riel +Date: Sun, 29 Sep 2024 02:36:41 -0400 +Subject: [PATCH] steamos-automount: Harden against missing /run/media + +When running against some systems, it is possible `/run/media` does not +exist when trying to unmount a path. E.g. with `UDISKS_FILESYSTEM_SHARED`. + +Signed-off-by: Samuel Dionne-Riel +--- + usr/lib/hwsupport/steamos-automount.sh | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/usr/lib/hwsupport/steamos-automount.sh b/usr/lib/hwsupport/steamos-automount.sh +index 8583ca7..0b0457f 100755 +--- a/usr/lib/hwsupport/steamos-automount.sh ++++ b/usr/lib/hwsupport/steamos-automount.sh +@@ -107,6 +107,7 @@ do_mount() + # that use the older mount point (for SD cards only). + case "${DEVBASE}" in + mmcblk0p*) ++ mkdir -p /run/media + if [[ -z "${ID_FS_LABEL}" ]]; then + old_mount_point="/run/media/${DEVBASE}" + else +@@ -124,6 +125,7 @@ do_mount() + + do_unmount() + { ++ mkdir -p /run/media + local mount_point=$(findmnt -fno TARGET "${DEVICE}" || true) + if [[ -n $mount_point ]]; then + # Remove symlink to the mount point that we're unmounting +-- +2.46.0 + diff --git a/pkgs/jupiter-hw-support/src.nix b/pkgs/jupiter-hw-support/src.nix index 61387797..d4fe36ea 100644 --- a/pkgs/jupiter-hw-support/src.nix +++ b/pkgs/jupiter-hw-support/src.nix @@ -27,6 +27,9 @@ stdenv.mkDerivation rec { ./hid-1.0.6.patch # Remove `deck` username assumption ./0001-Jovian-Ensure-automounting-works-for-any-UID-1000-us.patch + # Minor fixes against silly environments + ./0001-steamos-automount-Harden-against-missing-run-media.patch + ./0001-format-device-Harden-against-mountpoint-being-listed.patch ]; installPhase = '' From e35aa62b69a803e9eab5dee1170b2e877ad6caa1 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sun, 29 Sep 2024 23:41:25 -0400 Subject: [PATCH 07/11] jupiter-hw-support/polkit-helpers: Use --replace-fail --- pkgs/jupiter-hw-support/polkit-helpers.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/jupiter-hw-support/polkit-helpers.nix b/pkgs/jupiter-hw-support/polkit-helpers.nix index bf71d0d5..584e7c4d 100644 --- a/pkgs/jupiter-hw-support/polkit-helpers.nix +++ b/pkgs/jupiter-hw-support/polkit-helpers.nix @@ -80,7 +80,7 @@ in stdenv.mkDerivation { patchPhase = '' runHook prePatch - substituteInPlace usr/share/polkit-1/actions/org.valve.steamos.policy --replace /usr $out + substituteInPlace usr/share/polkit-1/actions/org.valve.steamos.policy --replace-fail /usr $out runHook postPatch ''; From 660806bb88e8f32eb5c84b9e7e18cb0efa4b1cfa Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sun, 29 Sep 2024 20:25:52 -0400 Subject: [PATCH 08/11] steam: Allow unmounting devices --- modules/steam/steam.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/steam/steam.nix b/modules/steam/steam.nix index b633940e..d7866c18 100644 --- a/modules/steam/steam.nix +++ b/modules/steam/steam.nix @@ -104,7 +104,7 @@ in # We don't support adopting a drive, yet. STEAM_ALLOW_DRIVE_ADOPT = mkDefault "0"; # Ejecting doesn't work, either. - STEAM_ALLOW_DRIVE_UNMOUNT = mkDefault "0"; + STEAM_ALLOW_DRIVE_UNMOUNT = mkDefault "1"; }; } ]); From 616d08e7852dcf89a1d623d4b6b910d3f50b0533 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sun, 29 Sep 2024 23:28:17 -0400 Subject: [PATCH 09/11] steam: Ensure steamos-manager can call umount --- modules/steam/steam.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/steam/steam.nix b/modules/steam/steam.nix index d7866c18..b801c0c5 100644 --- a/modules/steam/steam.nix +++ b/modules/steam/steam.nix @@ -68,6 +68,14 @@ in wantedBy = [ "gamescope-session.service" ]; }; + systemd.services.steamos-manager = { + overrideStrategy = "asDropin"; + path = [ + # .../lib/hwsupport/format-device.sh makes an unqualified `umount` call. + "/run/wrappers/" + ]; + }; + services.dbus.packages = [ pkgs.steamos-manager ]; services.displayManager.sessionPackages = [ pkgs.gamescope-session ]; From 00688654fac7a35604645918995974a8f7c8efac Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 4 Oct 2024 20:20:07 -0400 Subject: [PATCH 10/11] jupiter-hw-support: Update package description for what it's become --- pkgs/jupiter-hw-support/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/jupiter-hw-support/default.nix b/pkgs/jupiter-hw-support/default.nix index 10941194..049c99fb 100644 --- a/pkgs/jupiter-hw-support/default.nix +++ b/pkgs/jupiter-hw-support/default.nix @@ -105,11 +105,11 @@ stdenv.mkDerivation { meta = with lib; { description = '' - Steam Deck (Jupiter) hardware support package + Steam OS's generic “hardware support” package. - This package only contains the utility scripts as well as UCM files. - For the themes as well as unfree firmware, see the `steamdeck-theme` - and `steamdeck-firmware` packages. + This package contains the hardware-agnostic files from the `jupiter-hw-support` package. + + For themes, as well as unfree firmware, see the `steamdeck-theme` and `steamdeck-firmware` packages. ''; license = licenses.mit; }; From a4109a565aef7aed07ea294ce0ab9975020265fc Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 4 Oct 2024 20:23:12 -0400 Subject: [PATCH 11/11] automount: Move into `steamos` namespace The rules are generic. The `hw-support` package is, too, in practice. --- modules/devices/steamdeck/hw-support.nix | 13 ---------- modules/steamos/automount.nix | 32 ++++++++++++++++++++++++ modules/steamos/default.nix | 1 + 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 modules/steamos/automount.nix diff --git a/modules/devices/steamdeck/hw-support.nix b/modules/devices/steamdeck/hw-support.nix index dcda6745..88ca3015 100644 --- a/modules/devices/steamdeck/hw-support.nix +++ b/modules/devices/steamdeck/hw-support.nix @@ -14,14 +14,6 @@ in { options = { jovian.devices.steamdeck = { - enableAutoMountUdevRules = mkOption { - default = cfg.enable; - defaultText = lib.literalExpression "config.jovian.devices.steamdeck.enable"; - type = types.bool; - description = '' - Whether to enable udev rules to automatically mount SD cards upon insertion. - ''; - }; enableDefaultCmdlineConfig = mkOption { default = cfg.enable; defaultText = lib.literalExpression "config.jovian.devices.steamdeck.enable"; @@ -42,11 +34,6 @@ in }; config = mkMerge [ - (mkIf (cfg.enableAutoMountUdevRules) { - services.udev.packages = [ - pkgs.jupiter-hw-support - ]; - }) (mkIf (cfg.enableDefaultStage1Modules) { boot.initrd.kernelModules = [ "hid-generic" diff --git a/modules/steamos/automount.nix b/modules/steamos/automount.nix new file mode 100644 index 00000000..f8076a5a --- /dev/null +++ b/modules/steamos/automount.nix @@ -0,0 +1,32 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) + mkIf + mkMerge + mkOption + types + ; + cfg = config.jovian.steamos; +in +{ + options = { + jovian.steamos = { + enableAutoMountUdevRules = mkOption { + default = cfg.useSteamOSConfig; + defaultText = lib.literalExpression "config.jovian.steamos.useSteamOSConfig"; + type = types.bool; + description = '' + Whether to enable udev rules to automatically mount SD cards upon insertion. + ''; + }; + }; + }; + config = mkMerge [ + (mkIf (cfg.enableAutoMountUdevRules) { + services.udev.packages = [ + pkgs.jupiter-hw-support + ]; + }) + ]; +} diff --git a/modules/steamos/default.nix b/modules/steamos/default.nix index e0b4db44..c49fe235 100644 --- a/modules/steamos/default.nix +++ b/modules/steamos/default.nix @@ -8,6 +8,7 @@ let in { imports = [ + ./automount.nix ./bluetooth.nix ./boot.nix ./mesa.nix