libnvidia-container: clean up patches

This recreates the patches with `git format-patch` and adds descriptions to each of them. It also separates the binary and library lookup patches from each other.

+95 -50
+45
pkgs/by-name/li/libnvidia-container/0002-nvc-nvidia-docker-compatible-binary-lookups.patch
··· 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 5 + 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. 7 + --- 8 + src/nvc_info.c | 16 ++++++++++++++-- 9 + 1 file changed, 14 insertions(+), 2 deletions(-) 10 + 11 + diff --git a/src/nvc_info.c b/src/nvc_info.c 12 + index cf4b1905fd2127c28ee16649501be122d3be5261..2ab552860ef98879b76398a6f9be95f07b2c8a4a 100644 13 + --- a/src/nvc_info.c 14 + +++ b/src/nvc_info.c 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) 18 + { 19 + - char *env, *ptr; 20 + + char *env, *ptr, *os_path; 21 + const char *dir; 22 + char tmp[PATH_MAX]; 23 + char path[PATH_MAX]; 24 + int rv = -1; 25 + 26 + - if ((env = secure_getenv("PATH")) == NULL) { 27 + + if ((os_path = secure_getenv("PATH")) == NULL) { 28 + error_setx(err, "environment variable PATH not found"); 29 + return (-1); 30 + } 31 + + 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"); 37 + + return (-1); 38 + + } else if (p_rv < 0) { 39 + + error_setx(err, "error setting PATH environment variable"); 40 + + return (-1); 41 + + } 42 + + 43 + if ((env = ptr = xstrdup(err, env)) == NULL) 44 + return (-1); 45 +
+23
pkgs/by-name/li/libnvidia-container/0003-nvc-fix-struct-declaration.patch
··· 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:38:55 +0100 4 + Subject: [PATCH] nvc: fix struct declaration 5 + 6 + --- 7 + src/nvcgo.c | 3 ++- 8 + 1 file changed, 2 insertions(+), 1 deletion(-) 9 + 10 + diff --git a/src/nvcgo.c b/src/nvcgo.c 11 + index 2e090c9bef83e165dfb722ab27e3287407466173..643504cd485fbe4a89d5959a1adfb69ff6748576 100644 12 + --- a/src/nvcgo.c 13 + +++ b/src/nvcgo.c 14 + @@ -33,7 +33,8 @@ 15 + void nvcgo_program_1(struct svc_req *, register SVCXPRT *); 16 + 17 + static struct nvcgo_ext { 18 + - struct nvcgo; 19 + + struct rpc rpc; 20 + + struct libnvcgo api; 21 + bool initialized; 22 + void *dl_handle; 23 + } global_nvcgo_context;
+19 -30
pkgs/by-name/li/libnvidia-container/fix-library-resolving.patch pkgs/by-name/li/libnvidia-container/0001-ldcache-don-t-use-ldcache.patch
··· 1 - From 8799541f99785d2bd881561386676fb0985e939e Mon Sep 17 00:00:00 2001 1 + From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 2 2 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> 3 - Date: Thu, 10 Oct 2024 14:32:42 +0200 4 - Subject: [PATCH] fix library resolving 3 + Date: Fri, 20 Dec 2024 16:34:50 +0100 4 + Subject: [PATCH] ldcache: don't use ldcache 5 5 6 - Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> 6 + This patch hinders libnvidia-container from using the loader cache, which doesn't get used on NixOS. 7 7 --- 8 8 src/ldcache.c | 46 +++++++++++++++++----------------------------- 9 9 src/ldcache.h | 2 +- 10 - src/nvc_info.c | 10 +++------- 10 + src/nvc_info.c | 8 ++------ 11 11 src/nvc_ldcache.c | 2 +- 12 - 4 files changed, 22 insertions(+), 38 deletions(-) 12 + 4 files changed, 21 insertions(+), 37 deletions(-) 13 13 14 14 diff --git a/src/ldcache.c b/src/ldcache.c 15 - index 38bab055..8cd30a0f 100644 15 + index 38bab0553208f66b2866ccea6cdb0faca4357f19..1c4acd52b622be4ca6accdc80da5a6fcf9ae67dd 100644 16 16 --- a/src/ldcache.c 17 17 +++ b/src/ldcache.c 18 18 @@ -108,40 +108,28 @@ ldcache_close(struct ldcache *ctx) 19 - 19 + 20 20 int 21 21 ldcache_resolve(struct ldcache *ctx, uint32_t arch, const char *root, const char * const libs[], 22 22 - char *paths[], size_t size, ldcache_select_fn select, void *select_ctx) ··· 27 27 - int override; 28 28 + char dir[PATH_MAX]; 29 29 + char lib[PATH_MAX]; 30 - 30 + 31 31 - h = (struct header_libc6 *)ctx->ptr; 32 32 memset(paths, 0, size * sizeof(*paths)); 33 - 33 + 34 34 - for (uint32_t i = 0; i < h->nlibs; ++i) { 35 35 - int32_t flags = h->libs[i].flags; 36 36 - char *key = (char *)ctx->ptr + h->libs[i].key; ··· 74 74 return (0); 75 75 } 76 76 diff --git a/src/ldcache.h b/src/ldcache.h 77 - index 33d78dd7..2b087dbc 100644 77 + index 33d78dd7e21f65eb696535c115bbd2839a6c67ca..2b087dbca1a6a2946cd495e676a61e956212e3dc 100644 78 78 --- a/src/ldcache.h 79 79 +++ b/src/ldcache.h 80 80 @@ -50,6 +50,6 @@ void ldcache_init(struct ldcache *, struct error *, const char *); ··· 83 83 int ldcache_resolve(struct ldcache *, uint32_t, const char *, const char * const [], 84 84 - char *[], size_t, ldcache_select_fn, void *); 85 85 + char *[], size_t, const char*); 86 - 86 + 87 87 #endif /* HEADER_LDCACHE_H */ 88 88 diff --git a/src/nvc_info.c b/src/nvc_info.c 89 - index b7b8adfa..d42f2beb 100644 89 + index b7b8adfa7c79c326a1acb481a06a05d1463e810f..cf4b1905fd2127c28ee16649501be122d3be5261 100644 90 90 --- a/src/nvc_info.c 91 91 +++ b/src/nvc_info.c 92 92 @@ -217,15 +217,13 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_ ··· 95 95 ldcache_init(&ld, err, path); 96 96 - if (ldcache_open(&ld) < 0) 97 97 - return (-1); 98 - 98 + 99 99 info->nlibs = size; 100 100 info->libs = array_new(err, size); 101 101 if (info->libs == NULL) ··· 104 104 - info->libs, info->nlibs, select_libraries_fn, info) < 0) 105 105 + info->libs, info->nlibs, info->nvrm_version) < 0) 106 106 goto fail; 107 - 107 + 108 108 info->nlibs32 = size; 109 109 @@ -233,13 +231,11 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_ 110 110 if (info->libs32 == NULL) ··· 114 114 + info->libs32, info->nlibs32, info->nvrm_version) < 0) 115 115 goto fail; 116 116 rv = 0; 117 - 117 + 118 118 fail: 119 119 - if (ldcache_close(&ld) < 0) 120 120 - return (-1); 121 121 return (rv); 122 122 } 123 - 124 - @@ -253,7 +249,7 @@ find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_d 125 - char path[PATH_MAX]; 126 - int rv = -1; 127 - 128 - - if ((env = secure_getenv("PATH")) == NULL) { 129 - + if ((env = "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin") == NULL) { 130 - error_setx(err, "environment variable PATH not found"); 131 - return (-1); 132 - } 123 + 133 124 diff --git a/src/nvc_ldcache.c b/src/nvc_ldcache.c 134 - index db3b2f69..ae5def43 100644 125 + index db3b2f69692270e9058b2e26f18eb31677909d05..ae5def43b4cb3973af3aad55361265173ca938a7 100644 135 126 --- a/src/nvc_ldcache.c 136 127 +++ b/src/nvc_ldcache.c 137 128 @@ -367,7 +367,7 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt) 138 129 if (validate_args(ctx, cnt != NULL) < 0) 139 130 return (-1); 140 - 131 + 141 132 - argv = (char * []){cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL}; 142 133 + argv = (char * []){cnt->cfg.ldconfig, "-f", "/tmp/ld.so.conf.nvidia-host", "-C", "/tmp/ld.so.cache.nvidia-host", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL}; 143 134 if (*argv[0] == '@') { 144 135 /* 145 136 * We treat this path specially to be relative to the host filesystem. 146 - -- 147 - 2.46.0
-14
pkgs/by-name/li/libnvidia-container/inline-c-struct.patch
··· 1 - diff --git a/src/nvcgo.c b/src/nvcgo.c 2 - index 98789a3..47ad02b 100644 3 - --- a/src/nvcgo.c 4 - +++ b/src/nvcgo.c 5 - @@ -33,7 +33,8 @@ 6 - void nvcgo_program_1(struct svc_req *, register SVCXPRT *); 7 - 8 - static struct nvcgo_ext { 9 - - struct nvcgo; 10 - + struct rpc rpc; 11 - + struct libnvcgo api; 12 - bool initialized; 13 - void *dl_handle; 14 - } global_nvcgo_context;
+8 -6
pkgs/by-name/li/libnvidia-container/package.nix
··· 45 45 patches = [ 46 46 # Locations of nvidia driver libraries are not resolved via ldconfig which 47 47 # doesn't get used on NixOS. 48 - # TODO: The latter doesn't really apply anymore. 49 - # Additional support binaries like nvidia-smi 50 - # are not resolved via the environment PATH but via the derivation output 51 - # path. 52 - (replaceVars ./fix-library-resolving.patch { 48 + (replaceVars ./0001-ldcache-don-t-use-ldcache.patch { 53 49 inherit (addDriverRunpath) driverLink; 54 50 }) 55 51 52 + # Use both PATH and the legacy nvidia-docker paths (NixOS artifacts) 53 + # for binary lookups. 54 + # TODO: Remove the legacy compatibility once nvidia-docker is removed 55 + # from NixOS. 56 + ./0002-nvc-nvidia-docker-compatible-binary-lookups.patch 57 + 56 58 # fix bogus struct declaration 57 - ./inline-c-struct.patch 59 + ./0003-nvc-fix-struct-declaration.patch 58 60 ]; 59 61 60 62 postPatch = ''