tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
libnvidia-container: 1.9.0 -> 1.16.2
Moritz Sanft
1 year ago
60b56abc
fedeefb4
+113
-66
3 changed files
expand all
collapse all
unified
split
pkgs
by-name
li
libnvidia-container
fix-library-resolving.patch
modprobe.patch
package.nix
+47
-30
pkgs/by-name/li/libnvidia-container/libnvc-ldconfig-and-path-fixes.patch
pkgs/by-name/li/libnvidia-container/fix-library-resolving.patch
···
0
0
0
0
0
0
0
0
0
0
0
0
0
1
diff --git a/src/ldcache.c b/src/ldcache.c
2
-
index 38bab05..e1abc89 100644
3
--- a/src/ldcache.c
4
+++ b/src/ldcache.c
5
-
@@ -108,40 +108,27 @@ ldcache_close(struct ldcache *ctx)
6
-
7
int
8
ldcache_resolve(struct ldcache *ctx, uint32_t arch, const char *root, const char * const libs[],
9
- char *paths[], size_t size, ldcache_select_fn select, void *select_ctx)
···
14
- int override;
15
+ char dir[PATH_MAX];
16
+ char lib[PATH_MAX];
17
-
18
- h = (struct header_libc6 *)ctx->ptr;
19
memset(paths, 0, size * sizeof(*paths));
20
-
21
- for (uint32_t i = 0; i < h->nlibs; ++i) {
22
- int32_t flags = h->libs[i].flags;
23
- char *key = (char *)ctx->ptr + h->libs[i].key;
24
- char *value = (char *)ctx->ptr + h->libs[i].value;
25
-
26
- if (!(flags & LD_ELF) || (flags & LD_ARCH_MASK) != arch)
27
-
+ for (size_t j = 0; j < size; ++j) {
28
-
+ snprintf(dir, 100, "/run/opengl-driver%s/lib",
29
-
+ arch == LD_I386_LIB32 ? "-32" : "");
30
-
+ if (!strncmp(libs[j], "libvdpau_nvidia.so", 100))
31
-
+ strcat(dir, "/vdpau");
32
-
+ snprintf(lib, 100, "%s/%s.%s", dir, libs[j], version);
33
-
+ if (path_resolve_full(ctx->err, path, "/", lib) < 0)
34
-
+ return (-1);
35
-
+ if (!file_exists(ctx->err, path))
36
-
continue;
37
-
38
- for (size_t j = 0; j < size; ++j) {
39
- if (!str_has_prefix(key, libs[j]))
···
52
- }
53
- break;
54
- }
0
0
0
0
0
0
0
0
0
0
0
55
+ paths[j] = xstrdup(ctx->err, path);
56
+ if (paths[j] == NULL)
57
+ return (-1);
···
59
return (0);
60
}
61
diff --git a/src/ldcache.h b/src/ldcache.h
62
-
index 33d78dd..2b087db 100644
63
--- a/src/ldcache.h
64
+++ b/src/ldcache.h
65
@@ -50,6 +50,6 @@ void ldcache_init(struct ldcache *, struct error *, const char *);
···
68
int ldcache_resolve(struct ldcache *, uint32_t, const char *, const char * const [],
69
- char *[], size_t, ldcache_select_fn, void *);
70
+ char *[], size_t, const char*);
71
-
72
#endif /* HEADER_LDCACHE_H */
73
diff --git a/src/nvc_info.c b/src/nvc_info.c
74
-
index 30e3cfd..6d12a50 100644
75
--- a/src/nvc_info.c
76
+++ b/src/nvc_info.c
77
-
@@ -167,15 +167,13 @@ find_library_paths(struct error *err, struct nvc_driver_info *info, const char *
78
if (path_resolve_full(err, path, root, ldcache) < 0)
79
return (-1);
80
ldcache_init(&ld, err, path);
81
- if (ldcache_open(&ld) < 0)
82
- return (-1);
83
-
84
info->nlibs = size;
85
info->libs = array_new(err, size);
86
if (info->libs == NULL)
···
89
- info->libs, info->nlibs, select_libraries_fn, info) < 0)
90
+ info->libs, info->nlibs, info->nvrm_version) < 0)
91
goto fail;
92
-
93
info->nlibs32 = size;
94
-
@@ -183,13 +181,11 @@ find_library_paths(struct error *err, struct nvc_driver_info *info, const char *
95
if (info->libs32 == NULL)
96
goto fail;
97
if (ldcache_resolve(&ld, LIB32_ARCH, root, libs,
···
99
+ info->libs32, info->nlibs32, info->nvrm_version) < 0)
100
goto fail;
101
rv = 0;
102
-
103
fail:
104
- if (ldcache_close(&ld) < 0)
105
- return (-1);
106
return (rv);
107
}
108
-
109
-
@@ -203,7 +199,7 @@ find_binary_paths(struct error *err, struct nvc_driver_info *info, const char *r
110
char path[PATH_MAX];
111
int rv = -1;
112
-
113
- if ((env = secure_getenv("PATH")) == NULL) {
114
+ if ((env = "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin") == NULL) {
115
error_setx(err, "environment variable PATH not found");
116
return (-1);
117
}
118
diff --git a/src/nvc_ldcache.c b/src/nvc_ldcache.c
119
-
index 6ff380f..cbe6a69 100644
120
--- a/src/nvc_ldcache.c
121
+++ b/src/nvc_ldcache.c
122
-
@@ -340,7 +340,7 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
123
if (validate_args(ctx, cnt != NULL) < 0)
124
return (-1);
125
-
126
-
- argv = (char * []){cnt->cfg.ldconfig, cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
127
+ 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};
128
if (*argv[0] == '@') {
129
/*
130
* We treat this path specially to be relative to the host filesystem.
0
0
···
1
+
From 8799541f99785d2bd881561386676fb0985e939e Mon Sep 17 00:00:00 2001
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
5
+
6
+
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
7
+
---
8
+
src/ldcache.c | 46 +++++++++++++++++-----------------------------
9
+
src/ldcache.h | 2 +-
10
+
src/nvc_info.c | 10 +++-------
11
+
src/nvc_ldcache.c | 2 +-
12
+
4 files changed, 22 insertions(+), 38 deletions(-)
13
+
14
diff --git a/src/ldcache.c b/src/ldcache.c
15
+
index 38bab055..8cd30a0f 100644
16
--- a/src/ldcache.c
17
+++ b/src/ldcache.c
18
+
@@ -108,40 +108,28 @@ ldcache_close(struct ldcache *ctx)
19
+
20
int
21
ldcache_resolve(struct ldcache *ctx, uint32_t arch, const char *root, const char * const libs[],
22
- char *paths[], size_t size, ldcache_select_fn select, void *select_ctx)
···
27
- int override;
28
+ char dir[PATH_MAX];
29
+ char lib[PATH_MAX];
30
+
31
- h = (struct header_libc6 *)ctx->ptr;
32
memset(paths, 0, size * sizeof(*paths));
33
+
34
- for (uint32_t i = 0; i < h->nlibs; ++i) {
35
- int32_t flags = h->libs[i].flags;
36
- char *key = (char *)ctx->ptr + h->libs[i].key;
37
- char *value = (char *)ctx->ptr + h->libs[i].value;
38
-
39
- if (!(flags & LD_ELF) || (flags & LD_ARCH_MASK) != arch)
40
+
- continue;
0
0
0
0
0
0
0
0
0
41
-
42
- for (size_t j = 0; j < size; ++j) {
43
- if (!str_has_prefix(key, libs[j]))
···
56
- }
57
- break;
58
- }
59
+
+ for (size_t j = 0; j < size; ++j) {
60
+
+ snprintf(dir, 100, "@driverLink@/lib");
61
+
+
62
+
+ if (!strncmp(libs[j], "libvdpau_nvidia.so", 100))
63
+
+ strcat(dir, "/vdpau");
64
+
+ snprintf(lib, 100, "%s/%s.%s", dir, libs[j], version);
65
+
+ if (path_resolve_full(ctx->err, path, "/", lib) < 0)
66
+
+ return (-1);
67
+
+ if (!file_exists(ctx->err, path))
68
+
+ continue;
69
+
+
70
+ paths[j] = xstrdup(ctx->err, path);
71
+ if (paths[j] == NULL)
72
+ return (-1);
···
74
return (0);
75
}
76
diff --git a/src/ldcache.h b/src/ldcache.h
77
+
index 33d78dd7..2b087dbc 100644
78
--- a/src/ldcache.h
79
+++ b/src/ldcache.h
80
@@ -50,6 +50,6 @@ void ldcache_init(struct ldcache *, struct error *, const char *);
···
83
int ldcache_resolve(struct ldcache *, uint32_t, const char *, const char * const [],
84
- char *[], size_t, ldcache_select_fn, void *);
85
+ char *[], size_t, const char*);
86
+
87
#endif /* HEADER_LDCACHE_H */
88
diff --git a/src/nvc_info.c b/src/nvc_info.c
89
+
index b7b8adfa..d42f2beb 100644
90
--- a/src/nvc_info.c
91
+++ b/src/nvc_info.c
92
+
@@ -217,15 +217,13 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
93
if (path_resolve_full(err, path, root, ldcache) < 0)
94
return (-1);
95
ldcache_init(&ld, err, path);
96
- if (ldcache_open(&ld) < 0)
97
- return (-1);
98
+
99
info->nlibs = size;
100
info->libs = array_new(err, size);
101
if (info->libs == NULL)
···
104
- info->libs, info->nlibs, select_libraries_fn, info) < 0)
105
+ info->libs, info->nlibs, info->nvrm_version) < 0)
106
goto fail;
107
+
108
info->nlibs32 = size;
109
+
@@ -233,13 +231,11 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
110
if (info->libs32 == NULL)
111
goto fail;
112
if (ldcache_resolve(&ld, LIB32_ARCH, root, libs,
···
114
+ info->libs32, info->nlibs32, info->nvrm_version) < 0)
115
goto fail;
116
rv = 0;
117
+
118
fail:
119
- if (ldcache_close(&ld) < 0)
120
- return (-1);
121
return (rv);
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
}
133
diff --git a/src/nvc_ldcache.c b/src/nvc_ldcache.c
134
+
index db3b2f69..ae5def43 100644
135
--- a/src/nvc_ldcache.c
136
+++ b/src/nvc_ldcache.c
137
+
@@ -367,7 +367,7 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
138
if (validate_args(ctx, cnt != NULL) < 0)
139
return (-1);
140
+
141
+
- 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
+ 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
if (*argv[0] == '@') {
144
/*
145
* We treat this path specially to be relative to the host filesystem.
146
+
--
147
+
2.46.0
+9
-8
pkgs/by-name/li/libnvidia-container/modprobe.patch
···
1
diff -ruN nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c
2
-
--- nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c 2020-07-09 17:06:05.000000000 +0000
3
-
+++ nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c 2020-08-18 12:43:03.223871514 +0000
4
-
@@ -840,10 +840,10 @@
5
return mknod_helper(major, minor_num, vgpu_dev_name, NV_PROC_REGISTRY_PATH);
6
}
7
···
17
char field[32];
18
FILE *fp;
19
diff -ruN nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h
20
-
--- nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h 2020-07-09 17:06:05.000000000 +0000
21
-
+++ nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h 2020-08-18 12:43:44.227745050 +0000
22
-
@@ -81,6 +81,7 @@
23
int nvidia_nvswitch_get_file_state(int minor);
24
int nvidia_cap_mknod(const char* cap_file_path, int *minor);
25
int nvidia_cap_get_file_state(const char* cap_file_path);
26
+int nvidia_cap_get_device_file_attrs(const char* cap_file_path, int *major, int *minor, char *name);
0
0
27
int nvidia_get_chardev_major(const char *name);
28
-
29
-
#endif /* NV_LINUX */
···
1
diff -ruN nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c
2
+
--- nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c 2021-11-13 14:36:58.096684602 +0000
3
+
+++ nvidia-modprobe-@modprobeVersion@-patched/modprobe-utils/nvidia-modprobe-utils.c 2021-11-13 14:43:40.965146390 +0000
4
+
@@ -959,10 +959,10 @@
5
return mknod_helper(major, minor_num, vgpu_dev_name, NV_PROC_REGISTRY_PATH);
6
}
7
···
17
char field[32];
18
FILE *fp;
19
diff -ruN nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h
20
+
--- nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h 2021-11-13 14:36:58.096684602 +0000
21
+
+++ nvidia-modprobe-@modprobeVersion@-patched/modprobe-utils/nvidia-modprobe-utils.h 2021-11-13 14:38:34.078700961 +0000
22
+
@@ -87,6 +87,7 @@
23
int nvidia_nvswitch_get_file_state(int minor);
24
int nvidia_cap_mknod(const char* cap_file_path, int *minor);
25
int nvidia_cap_get_file_state(const char* cap_file_path);
26
+int nvidia_cap_get_device_file_attrs(const char* cap_file_path, int *major, int *minor, char *name);
27
+
int nvidia_cap_imex_channel_mknod(int minor);
28
+
int nvidia_cap_imex_channel_file_state(int minor);
29
int nvidia_get_chardev_major(const char *name);
30
+
int nvidia_msr_modprobe(void);
0
+57
-28
pkgs/by-name/li/libnvidia-container/package.nix
···
1
-
{ stdenv
2
-
, lib
3
-
, addDriverRunpath
4
-
, fetchFromGitHub
5
-
, pkg-config
6
-
, elfutils
7
-
, libcap
8
-
, libseccomp
9
-
, rpcsvc-proto
10
-
, libtirpc
11
-
, makeWrapper
12
-
, substituteAll
13
-
, removeReferencesTo
14
-
, go
0
0
15
}:
16
let
17
-
modprobeVersion = "495.44";
18
nvidia-modprobe = fetchFromGitHub {
19
owner = "NVIDIA";
20
repo = "nvidia-modprobe";
21
rev = modprobeVersion;
22
-
sha256 = "sha256-Y3ZOfge/EcmhqI19yWO7UfPqkvY1CHHvFC5l9vYyGuU=";
23
};
24
modprobePatch = substituteAll {
25
src = ./modprobe.patch;
···
28
in
29
stdenv.mkDerivation rec {
30
pname = "libnvidia-container";
31
-
version = "1.9.0";
32
33
src = fetchFromGitHub {
34
owner = "NVIDIA";
35
-
repo = pname;
36
rev = "v${version}";
37
-
sha256 = "sha256-7OTawWwjeKU8wIa8I/+aSvAJli4kEua94nJSNyCajpE=";
38
};
39
40
patches = [
41
-
# locations of nvidia-driver libraries are not resolved via ldconfig which
42
-
# doesn't get used on NixOS. Additional support binaries like nvidia-smi
0
0
43
# are not resolved via the environment PATH but via the derivation output
44
# path.
45
-
./libnvc-ldconfig-and-path-fixes.patch
0
0
46
47
# fix bogus struct declaration
48
./inline-c-struct.patch
···
53
-e 's/^REVISION ?=.*/REVISION = ${src.rev}/' \
54
-e 's/^COMPILER :=.*/COMPILER = $(CC)/' \
55
mk/common.mk
0
0
0
0
0
56
57
mkdir -p deps/src/nvidia-modprobe-${modprobeVersion}
58
cp -r ${nvidia-modprobe}/* deps/src/nvidia-modprobe-${modprobeVersion}
···
84
HOME="$(mktemp -d)"
85
'';
86
87
-
env.NIX_CFLAGS_COMPILE = toString [ "-I${libtirpc.dev}/include/tirpc" ];
88
-
NIX_LDFLAGS = [ "-L${libtirpc.dev}/lib" "-ltirpc" ];
0
0
0
89
90
-
nativeBuildInputs = [ pkg-config go rpcsvc-proto makeWrapper removeReferencesTo ];
0
0
0
0
0
0
91
92
-
buildInputs = [ elfutils libcap libseccomp libtirpc ];
0
0
0
0
0
93
94
makeFlags = [
95
"WITH_LIBELF=yes"
···
103
postInstall =
104
let
105
inherit (addDriverRunpath) driverLink;
106
-
libraryPath = lib.makeLibraryPath [ "$out" driverLink "${driverLink}-32" ];
0
0
0
0
107
in
108
''
109
-
remove-references-to -t "${go}" $out/lib/libnvidia-container-go.so.1.9.0
110
wrapProgram $out/bin/nvidia-container-cli --prefix LD_LIBRARY_PATH : ${libraryPath}
111
'';
112
disallowedReferences = [ go ];
···
1
+
{
2
+
stdenv,
3
+
lib,
4
+
addDriverRunpath,
5
+
fetchFromGitHub,
6
+
pkg-config,
7
+
elfutils,
8
+
libcap,
9
+
libseccomp,
10
+
rpcsvc-proto,
11
+
libtirpc,
12
+
makeWrapper,
13
+
substituteAll,
14
+
removeReferencesTo,
15
+
replaceVars,
16
+
go,
17
}:
18
let
19
+
modprobeVersion = "550.54.14";
20
nvidia-modprobe = fetchFromGitHub {
21
owner = "NVIDIA";
22
repo = "nvidia-modprobe";
23
rev = modprobeVersion;
24
+
sha256 = "sha256-iBRMkvOXacs/llTtvc/ZC5i/q9gc8lMuUHxMbu8A+Kg=";
25
};
26
modprobePatch = substituteAll {
27
src = ./modprobe.patch;
···
30
in
31
stdenv.mkDerivation rec {
32
pname = "libnvidia-container";
33
+
version = "1.16.2";
34
35
src = fetchFromGitHub {
36
owner = "NVIDIA";
37
+
repo = "libnvidia-container";
38
rev = "v${version}";
39
+
sha256 = "sha256-hX+2B+0kHiAC2lyo6kwe7DctPLJWgRdbhlc316OO3r8=";
40
};
41
42
patches = [
43
+
# Locations of nvidia driver libraries are not resolved via ldconfig which
44
+
# doesn't get used on NixOS.
45
+
# TODO: The latter doesn't really apply anymore.
46
+
# Additional support binaries like nvidia-smi
47
# are not resolved via the environment PATH but via the derivation output
48
# path.
49
+
(replaceVars ./fix-library-resolving.patch {
50
+
inherit (addDriverRunpath) driverLink;
51
+
})
52
53
# fix bogus struct declaration
54
./inline-c-struct.patch
···
59
-e 's/^REVISION ?=.*/REVISION = ${src.rev}/' \
60
-e 's/^COMPILER :=.*/COMPILER = $(CC)/' \
61
mk/common.mk
62
+
63
+
sed -i \
64
+
-e 's/^GIT_TAG ?=.*/GIT_TAG = ${version}/' \
65
+
-e 's/^GIT_COMMIT ?=.*/GIT_COMMIT = ${src.rev}/' \
66
+
versions.mk
67
68
mkdir -p deps/src/nvidia-modprobe-${modprobeVersion}
69
cp -r ${nvidia-modprobe}/* deps/src/nvidia-modprobe-${modprobeVersion}
···
95
HOME="$(mktemp -d)"
96
'';
97
98
+
env.NIX_CFLAGS_COMPILE = toString [ "-I${lib.getInclude libtirpc}/include/tirpc" ];
99
+
NIX_LDFLAGS = [
100
+
"-L${lib.getLib libtirpc}/lib"
101
+
"-ltirpc"
102
+
];
103
104
+
nativeBuildInputs = [
105
+
pkg-config
106
+
go
107
+
rpcsvc-proto
108
+
makeWrapper
109
+
removeReferencesTo
110
+
];
111
112
+
buildInputs = [
113
+
elfutils
114
+
libcap
115
+
libseccomp
116
+
libtirpc
117
+
];
118
119
makeFlags = [
120
"WITH_LIBELF=yes"
···
128
postInstall =
129
let
130
inherit (addDriverRunpath) driverLink;
131
+
libraryPath = lib.makeLibraryPath [
132
+
"$out"
133
+
driverLink
134
+
"${driverLink}-32"
135
+
];
136
in
137
''
138
+
remove-references-to -t "${go}" $out/lib/libnvidia-container-go.so.${version}
139
wrapProgram $out/bin/nvidia-container-cli --prefix LD_LIBRARY_PATH : ${libraryPath}
140
'';
141
disallowedReferences = [ go ];