Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG_DATA_DIRS instead of hardcoding /usr/share #425

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

jmbaur
Copy link
Contributor

@jmbaur jmbaur commented Mar 23, 2024

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.

@elezar
Copy link
Member

elezar commented Mar 25, 2024

Thanks for the PR @jmbaur.

I think this is related to #327 where the intent is to make locating these files more robust. What are your thoughts on that PR?

(I will also still give this a proper review).

@jmbaur
Copy link
Contributor Author

jmbaur commented Mar 25, 2024

I think this is related to #327 where the intent is to make locating these files more robust. What are your thoughts on that PR?

Looks like a good overall change! I think the existing XDG_DATA_DIRS environment variable may cover more use cases since a user is able to potentially spread out these config files among many directories that can still be captured in a single environment variable since it is a representation of one or more directories, but I don't see anything wrong with allowing for a way to override that altogether. One other nice thing with going the XDG route is that a user would potentially not have to pass any explicit args to nvidia-ctk, assuming the distro is already setting these environment variables correctly (assuming they stray from the default value of /usr/local/share:/usr/share).

@elezar
Copy link
Member

elezar commented Mar 25, 2024

I think this is related to #327 where the intent is to make locating these files more robust. What are your thoughts on that PR?

Looks like a good overall change! I think the existing XDG_DATA_DIRS environment variable may cover more use cases since a user is able to potentially spread out these config files among many directories that can still be captured in a single environment variable since it is a representation of one or more directories, but I don't see anything wrong with allowing for a way to override that altogether. One other nice thing with going the XDG route is that a user would potentially not have to pass any explicit args to nvidia-ctk, assuming the distro is already setting these environment variables correctly (assuming they stray from the default value of /usr/local/share:/usr/share).

Yes, I think adding an explicit check for the XDG_DATA_DIRS variable there may make sense. (Does it also make sense to rename Config* in terms of functions and variables to Data* instead?

Copy link
Member

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jmbaur.

Given the changes proposed in #327, we could also update this to the following (assuming that we rebase off those):

// xdgDataDirs finds the paths as specified in the environment variable XDG_DATA_DIRS.
// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html.
func xdgDataDirs() []string {
	if dirs, exists := os.LookupEnv("XDG_DATA_DIRS"); exists && dirs != "" {
		return normalizeSearchPaths(dirs)
	}

	return []string{"/usr/local/share", "/usr/share"}
}

internal/discover/graphics.go Outdated Show resolved Hide resolved
internal/discover/graphics.go Outdated Show resolved Hide resolved
@jmbaur jmbaur force-pushed the discover-use-xdg branch from 6d834a8 to 424961a Compare March 25, 2024 20:01
@jmbaur
Copy link
Contributor Author

jmbaur commented Mar 25, 2024

Yes, I think adding an explicit check for the XDG_DATA_DIRS variable there may make sense. (Does it also make sense to rename Config* in terms of functions and variables to Data* instead?

IMO Config* is easier to understand what is being referred to rather than Data*, but to each their own. I know there also exist other XDG environment variables that have CONFIG in the name, it just so happens that the environment variable that is useful in this context doesn't have that.

@jmbaur
Copy link
Contributor Author

jmbaur commented Mar 25, 2024

Thanks @jmbaur.

Given the changes proposed in #327, we could also update this to the following (assuming that we rebase off those):

// xdgDataDirs finds the paths as specified in the environment variable XDG_DATA_DIRS.
// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html.
func xdgDataDirs() []string {
	if dirs, exists := os.LookupEnv("XDG_DATA_DIRS"); exists && dirs != "" {
		return normalizeSearchPaths(dirs)
	}

	return []string{"/usr/local/share", "/usr/share"}
}

Actually looks like this change can be done now, doesn't seem to be dependent on #327, unless I'm missing something.

@elezar
Copy link
Member

elezar commented Mar 25, 2024

Actually looks like this change can be done now, doesn't seem to be dependent on #327, unless I'm missing something.

You're right, it's not dependent on #327 and should be applicable now.

@jmbaur jmbaur force-pushed the discover-use-xdg branch 2 times, most recently from 2877f6c to ed41ee1 Compare March 26, 2024 02:48
@jmbaur
Copy link
Contributor Author

jmbaur commented Mar 26, 2024

Changed to use NormalizeSearchPaths

@elezar
Copy link
Member

elezar commented Apr 11, 2024

@jmbaur I got around to merging #327 and have rebased your changes here. Please take a look to see if I missed anything.

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>
Signed-off-by: Evan Lezar <elezar@nvidia.com>
@elezar elezar force-pushed the discover-use-xdg branch from 0308cd1 to 5788e62 Compare April 11, 2024 15:13
Copy link
Member

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution @jmbaur.

@jmbaur
Copy link
Contributor Author

jmbaur commented Apr 11, 2024

@jmbaur I got around to merging #327 and have rebased your changes here. Please take a look to see if I missed anything.

Looks right to me! Thanks for rebasing

@elezar elezar merged commit 7a9bc14 into NVIDIA:main Apr 11, 2024
8 checks passed
@jmbaur jmbaur deleted the discover-use-xdg branch April 11, 2024 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants