Merge branch 'nvidia4' into 'master'

Draft: libglvnd support for steam and nvidia

See merge request nonguix/nonguix!213
This commit is contained in:
Jean-Baptiste Volatier 2023-05-13 06:09:52 +00:00
commit 3bda2a14db
4 changed files with 218 additions and 24 deletions

129
nongnu/packages/gl.scm Normal file
View File

@ -0,0 +1,129 @@
(define-module (nongnu packages gl)
#:use-module (guix build-system gnu)
#:use-module (gnu packages)
#:use-module (gnu packages audio)
#:use-module (gnu packages freedesktop)
#:use-module (gnu packages gnome)
#:use-module (gnu packages linux)
#:use-module (gnu packages toolkits)
#:use-module (gnu packages graphics)
#:use-module (gnu packages pulseaudio)
#:use-module (gnu packages gtk)
#:use-module (gnu packages autotools)
#:use-module (gnu packages pkg-config)
#:use-module (gnu packages python)
#:use-module (gnu packages xorg)
#:use-module (guix packages)
#:use-module (guix gexp)
#:use-module (guix utils)
#:use-module (guix transformations)
#:use-module (gnu packages gl))
(define-public gl-search-path (list
(search-path-specification
(variable "__EGL_VENDOR_LIBRARY_DIRS")
(files '("share/glvnd/egl_vendor.d")))
(search-path-specification
(variable "__EGL_EXTERNAL_PLATFORM_CONFIG_FILENAMES")
(files '("share/egl/egl_external_platform.d"))
(file-pattern ".*\\.json$")
(file-type 'regular))
(search-path-specification
(variable "VK_ICD_FILENAMES")
(files '("share/vulkan/icd.d"))
(file-pattern ".*\\.json$")
(file-type 'regular))
(search-path-specification
(variable "VK_LAYER_PATH")
(files '("share/vulkan/implicit_layer.d")))
(search-path-specification
(variable "VDPAU_DRIVER_PATH")
(files '("lib/vdpau")))
(search-path-specification
(variable "GBM_BACKENDS_PATH")
(files '("lib/gbm")))
(search-path-specification
(variable "GUIX_GL_PATH")
(files (list "lib/glvnd")))))
(define-public libglvnd-glfix
(package/inherit
libglvnd
(name "libglvnd-glfix")
(source
(origin
(inherit (package-source libglvnd))
(patches
(parameterize
((%patch-path
(map (lambda (directory)
(string-append directory "/nongnu/packages/patches"))
%load-path)))
(search-patches "glvnd.patch")))))))
(define-public mesa-glvnd
(package/inherit
mesa
(name "mesa-glvnd")
(arguments
(substitute-keyword-arguments (package-arguments mesa)
((#:configure-flags flags)
`(cons "-Dglvnd=true" ,flags))
((#:phases phases)
#~(modify-phases #$phases
(add-after 'install 'symlink-glvnd
(lambda _
(mkdir-p (string-append #$output "/lib/glvnd"))
(symlink (string-append #$output "/lib/libGLX_mesa.so.0")
(string-append #$output "/lib/glvnd/libGLX_mesa.so.0"))))))))
(propagated-inputs
`(("libglvnd" ,libglvnd-glfix)
,@(package-propagated-inputs mesa)))
(description (string-concatenate (list (package-description mesa) " Glvnd-enabled variant.")))))
(define rewrite-input-glvnd (package-input-rewriting `((,mesa . ,mesa-glvnd)
(,libglvnd . ,libglvnd-glfix))))
(define-public (rewrite-glvnd p)
(package
(inherit (rewrite-input-glvnd p))
(name (string-concatenate (list (package-name p) "-glvnd")))
(description (string-concatenate (list (package-description p) " Glvnd-enabled variant.")))
(native-search-paths gl-search-path)))
(define-public libepoxy-glvnd
(rewrite-glvnd libepoxy))
(define-public mesa-utils-glvnd
(rewrite-glvnd mesa-utils))
(define-public xdg-utils-glvnd
(rewrite-glvnd xdg-utils))
(define-public zenity-glvnd
(rewrite-glvnd zenity))
(define-public alsa-plugins-glvnd
(rewrite-glvnd alsa-plugins))
(define-public imgui-1.86-glvnd
(rewrite-glvnd imgui-1.86))
(define-public mangohud-glvnd
(rewrite-glvnd mangohud))
(define-public openal-glvnd
(rewrite-glvnd openal))
(define-public pulseaudio-glvnd
(rewrite-glvnd pulseaudio))
(define-public gtk+-glvnd
(rewrite-glvnd gtk+))
(define-public gtk+-2-glvnd
(rewrite-glvnd gtk+-2))
(define-public egl-wayland-glvnd
(rewrite-glvnd egl-wayland))

View File

@ -222,9 +222,13 @@ NVIDIA Management Library")
(ice-9 popen)
(ice-9 rdelim)
(ice-9 regex)
(ice-9 match)
(ice-9 textual-ports))
#:install-plan
#~`(("." "lib/" #:include-regexp ("^./[^/]+\\.so") #:exclude-regexp ("nvidia_drv\\.so" "libglxserver_nvidia\\.so\\..*"))
#~`((,(match
#$(or (%current-target-system) (%current-system))
("i686-linux" "32")
("x86_64-linux" ".")) "lib/" #:include-regexp ("^./[^/]+\\.so") #:exclude-regexp ("nvidia_drv\\.so" "libglxserver_nvidia\\.so\\..*"))
("." "share/nvidia/" #:include-regexp ("nvidia-application-profiles.*"))
("." "share/egl/egl_external_platform.d/" #:include-regexp (".*_nvidia_.*\\.json"))
("90-nvidia.rules" "lib/udev/rules.d/")
@ -334,8 +338,31 @@ KERNEL==\"nvidia_uvm\", RUN+=\"@sh@ -c '@mknod@ -m 666 /dev/nvidia-uvm-tools c $
(symlink (string-append "libglxserver_nvidia.so." #$version)
(string-append #$output "/lib/xorg/modules/extensions/" "libglxserver_nvidia.so"))
(symlink (string-append "libnvidia-allocator.so." #$version)
(string-append #$output "/lib/nvidia-drm_gbm.so" )))))))
(supported-systems '("x86_64-linux"))
(string-append #$output "/lib/nvidia-drm_gbm.so" ))
;; symlink libGLX_nvidia.so.0 to correct location
(mkdir-p (string-append #$output "/lib/glvnd"))
(symlink (string-append #$output "/lib/libGLX_nvidia.so.0")
(string-append #$output "/lib/glvnd/libGLX_nvidia.so.0"))
;; and vdpau
(mkdir-p (string-append #$output "/lib/vdpau"))
(symlink (string-append #$output "/lib/libvdpau_nvidia.so")
(string-append #$output "/lib/vdpau/libvdpau_nvidia.so"))
;; and gbm
(when (string=? #$(or
(%current-target-system)
(%current-system))
"x86_64-linux")
(mkdir-p (string-append #$output "/lib/gbm"))
(symlink (string-append #$output "/lib/libnvidia-egl-gbm.so")
(string-append #$output "/lib/gbm/libnvidia-egl-gbm.so"))))))))
(supported-systems '("x86_64-linux" "i686-linux"))
(native-inputs (list patchelf))
(inputs
(list `(,gcc "lib")

View File

@ -0,0 +1,46 @@
diff --git a/src/GLX/libglxmapping.c b/src/GLX/libglxmapping.c
index ff2c3a6..3ac21e9 100644
--- a/src/GLX/libglxmapping.c
+++ b/src/GLX/libglxmapping.c
@@ -28,6 +28,7 @@
#include <pthread.h>
#include <dlfcn.h>
#include <string.h>
+#include <sys/stat.h>
#if defined(HASH_DEBUG)
# include <stdio.h>
@@ -292,7 +293,33 @@ static char *ConstructVendorLibraryFilename(const char *vendorName)
char *filename;
int ret;
+ const char* env = NULL;
+ char **tokens;
+ int i;
+ struct stat st;
+
+ env = getenv("GUIX_GL_PATH");
+
+ if (env != NULL) {
+
+ tokens = SplitString(env, NULL, ":");
+
+ if (tokens != NULL) {
+ for (i=0; tokens[i] != NULL; i++) {
+ ret = glvnd_asprintf(&filename, "%s/libGLX_%s.so.0", tokens[i], vendorName);
+ if (ret >= 0) {
+ if (stat(filename, &st) == 0) {
+ free(tokens);
+
+ return filename;
+ }
+ }
+ }
+ }
+ free(tokens);
+ }
+
ret = glvnd_asprintf(&filename, "libGLX_%s.so.0", vendorName);
if (ret < 0) {
return NULL;

View File

@ -71,6 +71,7 @@
#:use-module (gnu packages llvm)
#:use-module (gnu packages logging)
#:use-module (nongnu packages nvidia)
#:use-module (nongnu packages gl)
#:use-module (gnu packages pciutils)
#:use-module (gnu packages pulseaudio)
#:use-module (gnu packages python)
@ -289,21 +290,6 @@ in the Guix store"
fhs-lib-dirs)))
#$output)))))
(define steam-ld.so.conf
(packages->ld.so.conf
(list (fhs-union `(,@steam-client-libs
,@steam-gameruntime-libs
,@fhs-min-libs)
#:name "fhs-union-64")
(fhs-union `(,@steam-client-libs
,@steam-gameruntime-libs
,@fhs-min-libs)
#:name "fhs-union-32"
#:system "i686-linux"))))
(define steam-ld.so.cache
(ld.so.conf->ld.so.cache steam-ld.so.conf))
(define (nonguix-container->package container)
"Return a package with wrapper script to launch the supplied container object
in a sandboxed FHS environment."
@ -546,8 +532,9 @@ application."
;; contains are directly to /gnu/store/. Instead, it could be generated with
;; a generic ld.so.conf and result in paths more typical in an FHS distro,
;; like /lib within the container. This may be useful for future compatibility.
(let* ((ld.so.conf steam-ld.so.conf)
(ld.so.cache steam-ld.so.cache)
(let* ((ld.so.conf (packages->ld.so.conf (list (ngc-union64 container)
(ngc-union32 container))))
(ld.so.cache (ld.so.conf->ld.so.cache ld.so.conf))
(pkg (ngc-wrap-package container))
(run (ngc-run container)))
(program-file
@ -687,6 +674,9 @@ 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
all games will be installed."))))
(define nvidia-libs
`(("nvidia-driver" ,nvidia-driver)))
(define-public steam-nvidia
(nonguix-container->package
(nonguix-container
@ -694,16 +684,18 @@ all games will be installed."))))
(wrap-package steam-client)
(run "/bin/steam")
(union64
(replace-mesa
(rewrite-glvnd
(fhs-union `(,@steam-client-libs
,@steam-gameruntime-libs
,@fhs-min-libs)
,@fhs-min-libs
,@nvidia-libs)
#:name "fhs-union-64")))
(union32
(replace-mesa
(rewrite-glvnd
(fhs-union `(,@steam-client-libs
,@steam-gameruntime-libs
,@fhs-min-libs)
,@fhs-min-libs
,@nvidia-libs)
#:name "fhs-union-32"
#:system "i686-linux")))
(link-files '("share/applications/steam.desktop"