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

libnvidia-container: include binaries from driver package #372320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,26 @@ From: Moritz Sanft <[email protected]>
Date: Fri, 20 Dec 2024 16:37:07 +0100
Subject: [PATCH] nvc: nvidia-docker-compatible binary lookups

This patch maintains compatibility with NixOS' `virtualisation.docker.enableNvidia` option (which is to be removed soon), while also enabling supplying a custom PATH, to work with the modern CDI-based approach.
This patch maintains compatibility with NixOS' `virtualisation.docker.enableNvidia` option (which is to be removed soon), while also including the driver package's path, to work with the modern CDI-based approach.
---
src/nvc_info.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
src/nvc_info.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/nvc_info.c b/src/nvc_info.c
index cf4b1905fd2127c28ee16649501be122d3be5261..2ab552860ef98879b76398a6f9be95f07b2c8a4a 100644
index cf4b1905fd2127c28ee16649501be122d3be5261..cdfa19721bc913d8e2adb96d106cd65ee6111623 100644
--- a/src/nvc_info.c
+++ b/src/nvc_info.c
@@ -243,16 +243,28 @@ static int
find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_driver_info* info,
const char *root, const char * const bins[], size_t size)
{
- char *env, *ptr;
+ char *env, *ptr, *os_path;
const char *dir;
char tmp[PATH_MAX];
@@ -249,10 +249,13 @@ find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_d
char path[PATH_MAX];
int rv = -1;

- if ((env = secure_getenv("PATH")) == NULL) {
+ if ((os_path = secure_getenv("PATH")) == NULL) {
+ // TODO: Remove this patch once `virtualisation.docker.enableNvidia` is removed from NixOS.
+ // It only exists to maintain compatibility with the old nvidia-docker package.
+ if ((env = "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:@driverLink@/bin") == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do late-binding for nixos (/run paths) but not other systems (e.g. via PATH), and why not just always use the early-bound @driverLink@/bin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm not mistaken, /run/nvidia-docker/bin are remnants of virtualisation.docker.enableNvidia. This patch goes back to always using that, while adding @driverLink@/bin. I had added additional support for PATH before (#366855), but things went south there as I introduced a bug. Looking back at that, I decided to go back to a static path, which I did in this PR.

error_setx(err, "environment variable PATH not found");
return (-1);
}
Comment on lines +20 to 25
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless you wanted to keep the if statement for some reason, I'm okay with this being removed entirely.

+
+ // TODO: Remove this patch once `virtualisation.docker.enableNvidia` is removed from NixOS.
+ // It only exists to maintain compatibility with the old nvidia-docker package.
+ int p_rv = snprintf(env, PATH_MAX, "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:%s", os_path);
+ if (p_rv >= PATH_MAX) {
+ error_setx(err, "PATH environment variable too long");
+ return (-1);
+ } else if (p_rv < 0) {
+ error_setx(err, "error setting PATH environment variable");
+ return (-1);
+ }
+
if ((env = ptr = xstrdup(err, env)) == NULL)
return (-1);
Expand Down
4 changes: 3 additions & 1 deletion pkgs/by-name/li/libnvidia-container/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ stdenv.mkDerivation rec {
# for binary lookups.
# TODO: Remove the legacy compatibility once nvidia-docker is removed
# from NixOS.
./0002-nvc-nvidia-docker-compatible-binary-lookups.patch
(replaceVars ./0002-nvc-nvidia-docker-compatible-binary-lookups.patch {
inherit (addDriverRunpath) driverLink;
})

# fix bogus struct declaration
./0003-nvc-fix-struct-declaration.patch
Expand Down