guix-epistemia

Personal Guix channel
Log | Files | Refs

steam.scm (7278B)


      1 (define-module (epistemia packages steam)
      2   #:use-module (guix packages)
      3   #:use-module (guix gexp)
      4   #:use-module (guix git-download)
      5   #:use-module (guix build-system trivial)
      6   #:use-module (guix build-system gnu)
      7   #:use-module (gnu packages compression)
      8   #:use-module (gnu packages vulkan)
      9   #:use-module (gnu packages xorg)
     10   #:use-module (gnu packages bash)
     11   #:use-module (gnu packages gl)
     12   #:use-module (nongnu packages game-client)
     13   #:use-module (nonguix multiarch-container)
     14   #:export (steam-beyond steam-beyond-layer))
     15 
     16 ;;;; WARNING: BAD AI SLOP BELOW
     17 ;; it was done because steamvr by default uses all gpus. this causes corruption: https://github.com/ValveSoftware/SteamVR-for-Linux/issues/888
     18 ;; existing solutions didn't work, but having an llm create a custom vulkan layer that exposes only a single gpu did work
     19 ;; then, steamvr doesn't do 90Hz in linux for the bigscreen beyond 2e while it did in monado: https://vronlinux.org/docs/hardware/bigscreen-beyond/
     20 ;; but monado can't share its mode setting with steamvr, so llm made a library stub
     21 ;; but that needed changes to vrcompositor-launch script in steamvr, so below packages were created instead so I don't need extra non-package wrapper scripts
     22 
     23 ;; Sources are plain files embedded in this module; no mutable checkout or
     24 ;; sandbox-local library is needed at runtime.
     25 (define-public steam-beyond-layer
     26   (package
     27     (name "steam-beyond-layer")
     28     (version "fbc144250aadc405b0d5b3837446dace9f828794")
     29     (source
     30      (origin
     31        (method git-fetch)
     32        (uri (git-reference
     33 	      (url "ssh://anongit@vineetk.net/bigscreen-beyond-vulkan-90hz")
     34 	      (commit version)))
     35        (file-name (git-file-name name version))
     36        (sha256
     37 	(base32 "1hzcdk48f7lvccwws0rk2cdczdp4by55pawjh1lx0x2v7xpf4r4s"))))
     38     (build-system gnu-build-system)
     39     (arguments
     40      (list
     41       #:tests? #f ; Hardware-dependent; verified against the Beyond on demiurge.
     42       #:phases
     43       #~(modify-phases %standard-phases
     44 	  (delete 'configure)
     45           (replace 'build
     46             (lambda _
     47               (invoke "gcc" "-D_GNU_SOURCE" "-shared" "-fPIC" "-O2"
     48                       "-Wall" "-Wextra" "headset-gpu-90hz.c"
     49                       "beyond-90hz-config.c"
     50                       "-Wl,--version-script=headset-gpu-90hz.exports"
     51                       "-o" "libheadset_gpu_c.so" "-ldl")))
     52           (replace 'install
     53             (lambda _
     54               (install-file "libheadset_gpu_c.so"
     55                             (string-append #$output "/lib"))
     56               (let ((manifest (string-append #$output
     57 					     "/share/vulkan/implicit_layer.d/steamvr-headset-gpu.json")))
     58                 (mkdir-p (dirname manifest))
     59                 (call-with-output-file manifest
     60                   (lambda (port)
     61                     (format port "{\"file_format_version\":\"1.0.0\",\"layer\":{\"name\":\"VK_LAYER_CUSTOM_headset_gpu\",\"type\":\"GLOBAL\",\"library_path\":\"~a/lib/libheadset_gpu_c.so\",\"api_version\":\"1.1.0\",\"implementation_version\":\"3\",\"description\":\"Beyond GPU selection and matched 90 Hz geometry\",\"enable_environment\":{\"STEAMVR_HEADSET_GPU\":\"1\"},\"disable_environment\":{\"DISABLE_VK_LAYER_CUSTOM_headset_gpu\":\"1\"}}}\n" #$output)))))))))
     62     (native-inputs (list vulkan-headers))
     63     (inputs (list zlib libxcb))
     64     (home-page "https://github.com/ValveSoftware/SteamVR-for-Linux")
     65     (synopsis "Beyond 90 Hz geometry and headset GPU selection for SteamVR")
     66     (description "Local Vulkan-layer and preload workaround for the Bigscreen
     67 Beyond on demiurge. Selects PCI 0000:07:00.0 and keeps 1920-per-eye geometry
     68 consistent with the actual 90 Hz display mode, without modifying SteamVR.")
     69     (license #f)))
     70 
     71 ;; Set LD_PRELOAD AFTER entering the FHS sandbox but BEFORE Steam starts its
     72 ;; alongside-steam launcher service. No SteamVR depot files need modification.
     73 (define steam-client-original
     74   (@@ (nongnu packages game-client) steam-client))
     75 
     76 (define steam-client-beyond
     77   (package
     78     (inherit steam-client-original)
     79     (name "steam-client-beyond")
     80     (source #f)
     81     (build-system trivial-build-system)
     82     (arguments
     83      (list
     84       #:modules '((guix build utils))
     85       #:builder
     86       #~(begin
     87           (use-modules (guix build utils) (ice-9 ftw))
     88           (mkdir-p (string-append #$output "/bin"))
     89           (for-each
     90            (lambda (name)
     91              (unless (member name '("." ".." "bin"))
     92                (symlink (string-append #$steam-client-original "/" name)
     93                         (string-append #$output "/" name))))
     94            (scandir #$steam-client-original))
     95           (let ((wrapper (string-append #$output "/bin/steam")))
     96             (call-with-output-file wrapper
     97               (lambda (port)
     98                 (format port "#!~a/bin/sh\n" #$bash-minimal)
     99                 (display "\
    100 export G_SLICE=always-malloc
    101 export DRI_PRIME=pci-0000_07_00_0
    102 export STEAMVR_HEADSET_GPU=1\n" port)
    103                 (format port "layer=\"~a/lib/libheadset_gpu_c.so\"\n" #$steam-beyond-layer)
    104                 (display "if [ ! -r \"$layer\" ]; then echo \"Missing Beyond layer: $layer\" >&2; exit 1; fi\n" port)
    105                 (display "export LD_PRELOAD=\"$layer${LD_PRELOAD:+:$LD_PRELOAD}\"\n" port)
    106                 (format port "exec ~a/bin/steam \"$@\"\n" #$steam-client-original)))
    107             (chmod wrapper #o755)))))
    108     (inputs (list steam-client-original bash-minimal))
    109     (native-inputs '())
    110     (propagated-inputs '())))
    111 
    112 (define steam-beyond-container
    113   (nonguix-container->package
    114    (nonguix-container
    115     (inherit (steam-container-for mesa
    116               #:extra-packages `(("steam-beyond-layer" ,steam-beyond-layer))))
    117     (wrap-package steam-client-beyond))))
    118 
    119 ;; Machine/session setup belongs to the package entry point, before the
    120 ;; container is entered. The inner client wrapper above handles variables
    121 ;; that Nonguix deliberately does not preserve across the sandbox boundary.
    122 (define-public steam-beyond
    123   (package
    124     (inherit steam-beyond-container)
    125     (build-system trivial-build-system)
    126     (arguments
    127      (list
    128       #:modules '((guix build utils))
    129       #:builder
    130       #~(begin
    131           (use-modules (guix build utils) (ice-9 ftw))
    132           (mkdir-p (string-append #$output "/bin"))
    133           (for-each
    134            (lambda (name)
    135              (unless (member name '("." ".." "bin"))
    136                (symlink (string-append #$steam-beyond-container "/" name)
    137                         (string-append #$output "/" name))))
    138            (scandir #$steam-beyond-container))
    139           (let ((wrapper (string-append #$output "/bin/steam")))
    140             (call-with-output-file wrapper
    141               (lambda (port)
    142                 (format port "#!~a/bin/sh\n" #$bash-minimal)
    143                 (display "export DISPLAY=\"${DISPLAY:-:0}\"\n" port)
    144                 (display "export XDG_RUNTIME_DIR=\"${XDG_RUNTIME_DIR:-/tmp/runtime-1000}\"\n" port)
    145                 (display "export DRI_PRIME=pci-0000_07_00_0\n" port)
    146                 (display "export GUIX_SANDBOX_EXTRA_SHARES=\"${GUIX_SANDBOX_EXTRA_SHARES:+$GUIX_SANDBOX_EXTRA_SHARES:}/data_hdd/games\"\n" port)
    147                 (format port "exec ~a/bin/steam \"$@\"\n" #$steam-beyond-container)))
    148             (chmod wrapper #o755)))))
    149     (inputs (list steam-beyond-container bash-minimal))))