From d6ca551d31ab32764e29b6507abae054fa99f34a Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:23:43 +0100 Subject: [PATCH 1/2] libnvidia-container: include binaries from driver package There's really no reason to require the binaries from the nvidia driver package to be passed to libnvidia-container via the PATH. We do the same thing via driverLink for the libraries already, so let's be consistent here. --- .../0002-nvc-nvidia-docker-compatible-binary-lookups.patch | 4 ++-- pkgs/by-name/li/libnvidia-container/package.nix | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch b/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch index 2a52ad2bd2404..11539da647330 100644 --- a/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch +++ b/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch @@ -9,7 +9,7 @@ This patch maintains compatibility with NixOS' `virtualisation.docker.enableNvid 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nvc_info.c b/src/nvc_info.c -index cf4b1905fd2127c28ee16649501be122d3be5261..2ab552860ef98879b76398a6f9be95f07b2c8a4a 100644 +index cf4b1905fd2127c28ee16649501be122d3be5261..a238fba3f4ff7786cd1a84b80b1f623553e2d377 100644 --- a/src/nvc_info.c +++ b/src/nvc_info.c @@ -243,16 +243,28 @@ static int @@ -31,7 +31,7 @@ index cf4b1905fd2127c28ee16649501be122d3be5261..2ab552860ef98879b76398a6f9be95f0 + + // 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); ++ int p_rv = snprintf(env, PATH_MAX, "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:@driverLink@/bin:%s", os_path); + if (p_rv >= PATH_MAX) { + error_setx(err, "PATH environment variable too long"); + return (-1); diff --git a/pkgs/by-name/li/libnvidia-container/package.nix b/pkgs/by-name/li/libnvidia-container/package.nix index 7f8e75e6ac9a1..0dbad9f0145c4 100644 --- a/pkgs/by-name/li/libnvidia-container/package.nix +++ b/pkgs/by-name/li/libnvidia-container/package.nix @@ -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 From 6e4ca5ceaa4c7411d9c3dad15627eb5e09fa2046 Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:53:04 +0100 Subject: [PATCH 2/2] libnvidia-container: fix segfault if PATH is actually set https://github.com/NixOS/nixpkgs/pull/366855/commits/24d9b8a7060b3fb7d64fa27ee9a745617185a189 introduced a bug, that, if `PATH` was actually set to a value when libnvidia-container was ran, caused a segfault. This fixes this bug by scrapping the dynamic `PATH` behavior in favor of simply using the driver package's `driverLink` abstraction for that, which is more fit for the purpose than `PATH` either way. --- ...dia-docker-compatible-binary-lookups.patch | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch b/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch index 11539da647330..8abcee55719d6 100644 --- a/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch +++ b/pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch @@ -3,42 +3,26 @@ From: Moritz Sanft <58110325+msanft@users.noreply.github.com> 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..a238fba3f4ff7786cd1a84b80b1f623553e2d377 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) { error_setx(err, "environment variable PATH not found"); return (-1); } -+ -+ // 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:@driverLink@/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);