1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Moritz Sanft <58110325+msanft@users.noreply.github.com>
3 Date: Fri, 20 Dec 2024 16:37:07 +0100
4 Subject: [PATCH] nvc: nvidia-docker-compatible binary lookups
6 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.
8 src/nvc_info.c | 16 ++++++++++++++--
9 1 file changed, 14 insertions(+), 2 deletions(-)
11 diff --git a/src/nvc_info.c b/src/nvc_info.c
12 index cf4b1905fd2127c28ee16649501be122d3be5261..2ab552860ef98879b76398a6f9be95f07b2c8a4a 100644
15 @@ -243,16 +243,28 @@ static int
16 find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_driver_info* info,
17 const char *root, const char * const bins[], size_t size)
20 + char *env, *ptr, *os_path;
26 - if ((env = secure_getenv("PATH")) == NULL) {
27 + if ((os_path = secure_getenv("PATH")) == NULL) {
28 error_setx(err, "environment variable PATH not found");
32 + // TODO: Remove this patch once `virtualisation.docker.enableNvidia` is removed from NixOS.
33 + // It only exists to maintain compatibility with the old nvidia-docker package.
34 + int p_rv = snprintf(env, PATH_MAX, "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:%s", os_path);
35 + if (p_rv >= PATH_MAX) {
36 + error_setx(err, "PATH environment variable too long");
38 + } else if (p_rv < 0) {
39 + error_setx(err, "error setting PATH environment variable");
43 if ((env = ptr = xstrdup(err, env)) == NULL)