nongnu: steam: Add command line flag for switching asound.conf to 32-bit

* nongnu/packages/steam-client.scm (nongnu-container->package)
    (make-container-internal): Remove auto generated asound.conf.
    (make-internal-script): Use inline asound.conf and add --asound32 command line
    flag to set it as 32-bit instead of 64-bit.
    (steam-client, steam): Add new .desktop file for 32-bit asound.conf.
This commit is contained in:
ison 2021-05-26 05:16:41 -06:00
parent 954a6e9ac2
commit abeb450f0f
No known key found for this signature in database
GPG key ID: 5E76B1AD0FC22F93

View file

@ -139,9 +139,15 @@
(("/usr") (assoc-ref %outputs "out"))))) (("/usr") (assoc-ref %outputs "out")))))
(add-after 'patch-dot-desktop-files 'patch-desktop-file (add-after 'patch-dot-desktop-files 'patch-desktop-file
(lambda _ (lambda _
(substitute* (string-append (assoc-ref %outputs "out") (let ((path (string-append (assoc-ref %outputs "out")
"/share/applications/steam.desktop") "/share/applications/")))
(("Exec=.*/steam") "Exec=steam")))) (substitute* (string-append path "steam.desktop")
(("Exec=.*/steam") "Exec=steam"))
(copy-file (string-append path "steam.desktop")
(string-append path "steam-asound32.desktop"))
(substitute* (string-append path "steam-asound32.desktop")
(("Exec=steam %U") "Exec=steam %U -- --asound32")
(("Name=Steam") "Name=Steam (32-bit ALSA)")))))
;; Steamdeps installs missing packages, which doesn't work with Guix. ;; Steamdeps installs missing packages, which doesn't work with Guix.
(add-after 'install-binaries 'post-install (add-after 'install-binaries 'post-install
(lambda* (#:key inputs outputs #:allow-other-keys) (lambda* (#:key inputs outputs #:allow-other-keys)
@ -231,10 +237,7 @@
(define (nonguix-container->package container) (define (nonguix-container->package container)
"Return a package with wrapper script to launch the supplied container object "Return a package with wrapper script to launch the supplied container object
in a sandboxed FHS environment." in a sandboxed FHS environment."
(let* ((alsa-config ((@@ (gnu services sound) alsa-config-file) (let* ((fhs-internal (make-container-internal container))
((@ (gnu services sound) alsa-configuration)
(alsa-plugins (to32 alsa-plugins)))))
(fhs-internal (make-container-internal container alsa-config))
(fhs-manifest (make-container-manifest container fhs-internal)) (fhs-manifest (make-container-manifest container fhs-internal))
(fhs-wrapper (make-container-wrapper container fhs-manifest fhs-internal)) (fhs-wrapper (make-container-wrapper container fhs-manifest fhs-internal))
(pkg (ngc-wrap-package container))) (pkg (ngc-wrap-package container)))
@ -243,8 +246,7 @@ in a sandboxed FHS environment."
(version (or (ngc-version container) (version (or (ngc-version container)
(package-version pkg))) (package-version pkg)))
(source #f) (source #f)
(inputs `(("alsa-config" ,alsa-config) (inputs `(("wrap-package" ,(ngc-wrap-package container))
("wrap-package" ,(ngc-wrap-package container))
,@(if (null? (ngc-union64 container)) ,@(if (null? (ngc-union64 container))
'() '()
`(("fhs-union-64" ,(ngc-union64 container)))) `(("fhs-union-64" ,(ngc-union64 container))))
@ -261,8 +263,6 @@ in a sandboxed FHS environment."
(begin (begin
(use-modules (guix build utils)) (use-modules (guix build utils))
(let* ((out (assoc-ref %outputs "out")) (let* ((out (assoc-ref %outputs "out"))
(alsa-target (assoc-ref %build-inputs "alsa-config"))
(alsa-dest (string-append out "/etc/asound.conf"))
(internal-target (string-append (assoc-ref %build-inputs "fhs-internal") (internal-target (string-append (assoc-ref %build-inputs "fhs-internal")
"/bin/" ,(ngc-internal-name container))) "/bin/" ,(ngc-internal-name container)))
(internal-dest (string-append out "/sbin/" ,(ngc-internal-name container))) (internal-dest (string-append out "/sbin/" ,(ngc-internal-name container)))
@ -274,7 +274,6 @@ in a sandboxed FHS environment."
(mkdir-p (string-append out "/sbin")) (mkdir-p (string-append out "/sbin"))
(mkdir-p (string-append out "/etc")) (mkdir-p (string-append out "/etc"))
(mkdir-p (string-append out "/bin")) (mkdir-p (string-append out "/bin"))
(symlink alsa-target alsa-dest)
(symlink internal-target internal-dest) (symlink internal-target internal-dest)
(symlink wrapper-target wrapper-dest) (symlink wrapper-target wrapper-dest)
(symlink manifest-target manifest-dest) (symlink manifest-target manifest-dest)
@ -410,15 +409,14 @@ the exact path for the fhs-internal package."
#$(file-append (ngc-union32 container)) #$(file-append (ngc-union32 container))
#$(file-append fhs-internal))))))) #$(file-append fhs-internal)))))))
(define (make-container-internal container alsa-config) (define (make-container-internal container)
"Return a dummy package housing the fhs-internal script." "Return a dummy package housing the fhs-internal script."
(package (package
(name (ngc-internal-name container)) (name (ngc-internal-name container))
(version (or (ngc-version container) (version (or (ngc-version container)
(package-version (ngc-wrap-package container)))) (package-version (ngc-wrap-package container))))
(source #f) (source #f)
(inputs `(("alsa-config" ,alsa-config) (inputs `(("fhs-internal-script" ,(make-internal-script container))))
("fhs-internal-script" ,(make-internal-script container alsa-config))))
(build-system trivial-build-system) (build-system trivial-build-system)
(arguments (arguments
`(#:modules ((guix build utils)) `(#:modules ((guix build utils))
@ -436,7 +434,7 @@ the exact path for the fhs-internal package."
environment.") environment.")
(license #f))) (license #f)))
(define (make-internal-script container alsa-config) (define (make-internal-script container)
"Return an fhs-internal script which is used to perform additional steps to "Return an fhs-internal script which is used to perform additional steps to
set up the environment inside an FHS container before launching the desired set up the environment inside an FHS container before launching the desired
application." application."
@ -445,9 +443,11 @@ application."
(program-file (program-file
(ngc-internal-name container) (ngc-internal-name container)
(with-imported-modules (with-imported-modules
`((guix build utils)) `((guix build utils)
(ice-9 getopt-long))
#~(begin #~(begin
(use-modules (guix build utils)) (use-modules (guix build utils)
(ice-9 getopt-long))
(define (path->str path) (define (path->str path)
(if (list? path) (if (list? path)
(string-join path "/") (string-join path "/")
@ -460,11 +460,16 @@ application."
(define (icd-symlink file) (define (icd-symlink file)
(new-symlink (new-symlink
`(,file . ("/usr/share/vulkan/icd.d" ,(basename file))))) `(,file . ("/usr/share/vulkan/icd.d" ,(basename file)))))
(let ((guix-env (getenv "GUIX_ENVIRONMENT")) (define fhs-option-spec
(alsa-config #$(file-append alsa-config)) '((asound32 (value #f))))
(let* ((guix-env (getenv "GUIX_ENVIRONMENT"))
(union64 #$(file-append (ngc-union64 container))) (union64 #$(file-append (ngc-union64 container)))
(union32 #$(file-append (ngc-union32 container))) (union32 #$(file-append (ngc-union32 container)))
(args (cdr (command-line)))) (all-args (cdr (command-line)))
(fhs-args (member "--" all-args))
(steam-args (if fhs-args
(reverse (cdr (member "--" (reverse all-args))))
all-args)))
(delete-file "/bin/sh") (delete-file "/bin/sh")
(rmdir "/bin") (rmdir "/bin")
(for-each (for-each
@ -476,8 +481,7 @@ application."
"/usr/share/vulkan/icd.d")) "/usr/share/vulkan/icd.d"))
(for-each (for-each
new-symlink new-symlink
`((,alsa-config . "/etc/asound.conf") `(((,guix-env "etc/ssl") . "/etc/ssl")
((,guix-env "etc/ssl") . "/etc/ssl")
((,guix-env "etc/ssl") . "/run/current-system/profile/etc/ssl") ((,guix-env "etc/ssl") . "/run/current-system/profile/etc/ssl")
((,union32 "lib") . "/lib") ((,union32 "lib") . "/lib")
((,union32 "lib") . "/run/current-system/profile/lib") ((,union32 "lib") . "/run/current-system/profile/lib")
@ -497,7 +501,41 @@ application."
#:directories? #t) #:directories? #t)
,@(find-files (string-append union64 "/share/vulkan/icd.d") ,@(find-files (string-append union64 "/share/vulkan/icd.d")
#:directories? #t))) #:directories? #t)))
(apply system* `(#$(file-append pkg run) ,@args))))))))
;; Process FHS-specific command line options
(let* ((options (getopt-long (or fhs-args '("")) fhs-option-spec))
(asound32-opt (option-ref options 'asound32 #f))
(asound-lib (if asound32-opt "lib" "lib64")))
(if asound32-opt
(display "\n\n/etc/asound.conf configured for 32-bit.\n\n\n")
(display "\n\n/etc/asound.conf configured for 64-bit.\nLaunch steam with \"steam -- --asound32\" to use 32-bit instead.\n\n\n"))
(with-output-to-file "/etc/asound.conf"
(lambda _ (format (current-output-port) "# Generated by steam-client
# Use PulseAudio by default
pcm_type.pulse {
lib \"/~a/alsa-lib/libasound_module_pcm_pulse.so\"
}
ctl_type.pulse {
lib \"/~a/alsa-lib/libasound_module_ctl_pulse.so\"
}
pcm.!default {
type pulse
fallback \"sysdefault\"
hint {
show on
description \"Default ALSA Output (currently PulseAudio Sound Server)\"
}
}
ctl.!default {
type pulse
fallback \"sysdefault\"
}\n\n" asound-lib asound-lib))))
(apply system* `(#$(file-append pkg run) ,@steam-args))))))))
(define-public steam (define-public steam
(nonguix-container->package (nonguix-container->package
@ -516,7 +554,8 @@ application."
,@fhs-min-libs) ,@fhs-min-libs)
#:name "fhs-union-32" #:name "fhs-union-32"
#:system "i686-linux")) #:system "i686-linux"))
(link-files '("share/applications/steam.desktop")) (link-files '("share/applications/steam.desktop"
"share/applications/steam-asound32.desktop"))
(description "Steam is a digital software distribution platform created by (description "Steam is a digital software distribution platform created by
Valve. This package provides a script for launching Steam in a Guix container Valve. This package provides a script for launching Steam in a Guix container
which will use the directory @file{$HOME/.local/share/guix-sandbox-home} where which will use the directory @file{$HOME/.local/share/guix-sandbox-home} where