Skip to content

Commit 424961a

Browse files
committed
Use XDG_DATA_DIRS instead of hardcoding /usr/share
When running nvidia-ctk on a system that uses a custom XDG_DATA_DIRS environment variable value, the configuration files for `glvnd`, `vulkan`, and `egl` fail to get passed through from the host to the container. Reading from XDG_DATA_DIRS instead of hardcoding the default value allows for finding said files so they can be mounted in the container. Signed-off-by: Jared Baur <jaredbaur@fastmail.com>
1 parent 1ddc859 commit 424961a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

internal/discover/graphics.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n
5959
},
6060
)
6161

62+
searchPaths := []string{"/etc"}
63+
searchPaths = append(searchPaths, xdgDataDirs()...)
64+
6265
jsonMounts := NewMounts(
6366
logger,
6467
lookup.NewFileLocator(
6568
lookup.WithLogger(logger),
6669
lookup.WithRoot(driver.Root),
67-
lookup.WithSearchPaths("/etc", "/usr/share"),
70+
lookup.WithSearchPaths(searchPaths...),
6871
),
6972
driver.Root,
7073
[]string{
@@ -295,7 +298,7 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa
295298
lookup.NewFileLocator(
296299
lookup.WithLogger(logger),
297300
lookup.WithRoot(driver.Root),
298-
lookup.WithSearchPaths("/usr/share"),
301+
lookup.WithSearchPaths(xdgDataDirs()...),
299302
),
300303
driver.Root,
301304
[]string{"X11/xorg.conf.d/10-nvidia.conf"},
@@ -371,3 +374,15 @@ func (s selectDeviceByPath) MountIsSelected(Mount) bool {
371374
func (s selectDeviceByPath) HookIsSelected(Hook) bool {
372375
return true
373376
}
377+
378+
// xdgDataDirs finds the paths as specified in the environment variable XDG_DATA_DIRS.
379+
// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html.
380+
func xdgDataDirs() []string {
381+
dirs, exists := os.LookupEnv("XDG_DATA_DIRS")
382+
383+
if !exists || dirs == "" {
384+
return []string{"/usr/local/share", "/usr/share"}
385+
}
386+
387+
return filepath.SplitList(dirs, ":")
388+
}

0 commit comments

Comments
 (0)