push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Date: Fri, 20 Dec 2024 16:34:50 +0100
Subject: [PATCH] ldcache: don't use ldcache
This patch hinders libnvidia-container from using the loader cache, which doesn't get used on NixOS.
---
src/ldcache.c | 46 +++++++++++++++++-----------------------------
src/ldcache.h | 2 +-
src/nvc_info.c | 8 ++------
src/nvc_ldcache.c | 4 ++--
4 files changed, 22 insertions(+), 38 deletions(-)
diff --git a/src/ldcache.c b/src/ldcache.c
index 38bab0553208f66b2866ccea6cdb0faca4357f19..1c4acd52b622be4ca6accdc80da5a6fcf9ae67dd 100644
--- a/src/ldcache.c
+++ b/src/ldcache.c
@@ -108,40 +108,28 @@ ldcache_close(struct ldcache *ctx)
int
ldcache_resolve(struct ldcache *ctx, uint32_t arch, const char *root, const char * const libs[],
- char *paths[], size_t size, ldcache_select_fn select, void *select_ctx)
+ char *paths[], size_t size, const char* version)
{
char path[PATH_MAX];
- struct header_libc6 *h;
- int override;
+ char dir[PATH_MAX];
+ char lib[PATH_MAX];
- h = (struct header_libc6 *)ctx->ptr;
memset(paths, 0, size * sizeof(*paths));
- for (uint32_t i = 0; i < h->nlibs; ++i) {
- int32_t flags = h->libs[i].flags;
- char *key = (char *)ctx->ptr + h->libs[i].key;
- char *value = (char *)ctx->ptr + h->libs[i].value;
-
- if (!(flags & LD_ELF) || (flags & LD_ARCH_MASK) != arch)
- continue;
-
- for (size_t j = 0; j < size; ++j) {
- if (!str_has_prefix(key, libs[j]))
- continue;
- if (path_resolve(ctx->err, path, root, value) < 0)
- return (-1);
- if (paths[j] != NULL && str_equal(paths[j], path))
- continue;
- if ((override = select(ctx->err, select_ctx, root, paths[j], path)) < 0)
- return (-1);
- if (override) {
- free(paths[j]);
- paths[j] = xstrdup(ctx->err, path);
- if (paths[j] == NULL)
- return (-1);
- }
- break;
- }
+ for (size_t j = 0; j < size; ++j) {
+ snprintf(dir, 100, "@driverLink@/lib");
+
+ if (!strncmp(libs[j], "libvdpau_nvidia.so", 100))
+ strcat(dir, "/vdpau");
+ snprintf(lib, 100, "%s/%s.%s", dir, libs[j], version);
+ if (path_resolve_full(ctx->err, path, "/", lib) < 0)
+ return (-1);
+ if (!file_exists(ctx->err, path))
+ continue;
+
+ paths[j] = xstrdup(ctx->err, path);
+ if (paths[j] == NULL)
+ return (-1);
}
return (0);
}
diff --git a/src/ldcache.h b/src/ldcache.h
index 33d78dd7e21f65eb696535c115bbd2839a6c67ca..2b087dbca1a6a2946cd495e676a61e956212e3dc 100644
--- a/src/ldcache.h
+++ b/src/ldcache.h
@@ -50,6 +50,6 @@ void ldcache_init(struct ldcache *, struct error *, const char *);
int ldcache_open(struct ldcache *);
int ldcache_close(struct ldcache *);
int ldcache_resolve(struct ldcache *, uint32_t, const char *, const char * const [],
- char *[], size_t, ldcache_select_fn, void *);
+ char *[], size_t, const char*);
#endif /* HEADER_LDCACHE_H */
diff --git a/src/nvc_info.c b/src/nvc_info.c
index bcc887b2345bd42a098f9b85d9c66fae2775f736..5eaef61ada5e955ab11c6a4eb8429c50468e3370 100644
--- a/src/nvc_info.c
+++ b/src/nvc_info.c
@@ -217,15 +217,13 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
if (path_resolve_full(err, path, root, ldcache) < 0)
return (-1);
ldcache_init(&ld, err, path);
- if (ldcache_open(&ld) < 0)
- return (-1);
info->nlibs = size;
info->libs = array_new(err, size);
if (info->libs == NULL)
goto fail;
if (ldcache_resolve(&ld, LIB_ARCH, root, libs,
- info->libs, info->nlibs, select_libraries_fn, info) < 0)
+ info->libs, info->nlibs, info->nvrm_version) < 0)
goto fail;
info->nlibs32 = size;
@@ -233,13 +231,11 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
if (info->libs32 == NULL)
goto fail;
if (ldcache_resolve(&ld, LIB32_ARCH, root, libs,
- info->libs32, info->nlibs32, select_libraries_fn, info) < 0)
+ info->libs32, info->nlibs32, info->nvrm_version) < 0)
goto fail;
rv = 0;
fail:
- if (ldcache_close(&ld) < 0)
- return (-1);
return (rv);
}
diff --git a/src/nvc_ldcache.c b/src/nvc_ldcache.c
index 0535090dafbae5a00acb707bbbb5a35dbcea4a7a..5de429f4c2ea62775403a5fc1ed0f23a6c88655c 100644
--- a/src/nvc_ldcache.c
+++ b/src/nvc_ldcache.c
@@ -482,8 +482,8 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
* See https://github.com/NVIDIA/libnvidia-container/issues/316 for an
* in-depth investigation.
*/
- char *argv_default[] = {cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
- char *argv_with_compat_dir[] = {cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cuda_compat_dir, cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
+ char *argv_default[] = {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};
+ char *argv_with_compat_dir[] = {cnt->cfg.ldconfig, "-f", "/tmp/ld.so.conf.nvidia-host", "-C", "/tmp/ld.so.cache.nvidia-host", cnt->cuda_compat_dir, cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
if ((cnt->flags & OPT_CUDA_COMPAT_MODE_LDCONFIG) && (cnt->cuda_compat_dir != NULL)) {
/*
* We include the cuda_compat_dir directory on the ldconfig

View File

@@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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 including the driver package's path, to work with the modern CDI-based approach.
---
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 5eaef61ada5e955ab11c6a4eb8429c50468e3370..cac87500213e961e603494ac842d02522fc46a5e 100644
--- a/src/nvc_info.c
+++ b/src/nvc_info.c
@@ -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) {
+ // 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);
}
+
if ((env = ptr = xstrdup(err, env)) == NULL)
return (-1);

View File

@@ -0,0 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Date: Fri, 20 Dec 2024 16:38:55 +0100
Subject: [PATCH] nvc: fix struct declaration
---
src/nvcgo.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/nvcgo.c b/src/nvcgo.c
index 2e090c9bef83e165dfb722ab27e3287407466173..643504cd485fbe4a89d5959a1adfb69ff6748576 100644
--- a/src/nvcgo.c
+++ b/src/nvcgo.c
@@ -33,7 +33,8 @@
void nvcgo_program_1(struct svc_req *, register SVCXPRT *);
static struct nvcgo_ext {
- struct nvcgo;
+ struct rpc rpc;
+ struct libnvcgo api;
bool initialized;
void *dl_handle;
} global_nvcgo_context;

View File

@@ -0,0 +1,30 @@
diff -ruN nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c
--- nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.c 2021-11-13 14:36:58.096684602 +0000
+++ nvidia-modprobe-@modprobeVersion@-patched/modprobe-utils/nvidia-modprobe-utils.c 2021-11-13 14:43:40.965146390 +0000
@@ -959,10 +959,10 @@
return mknod_helper(major, minor_num, vgpu_dev_name, NV_PROC_REGISTRY_PATH);
}
-static int nvidia_cap_get_device_file_attrs(const char* cap_file_path,
- int *major,
- int *minor,
- char *name)
+int nvidia_cap_get_device_file_attrs(const char* cap_file_path,
+ int *major,
+ int *minor,
+ char *name)
{
char field[32];
FILE *fp;
diff -ruN nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h
--- nvidia-modprobe-@modprobeVersion@/modprobe-utils/nvidia-modprobe-utils.h 2021-11-13 14:36:58.096684602 +0000
+++ nvidia-modprobe-@modprobeVersion@-patched/modprobe-utils/nvidia-modprobe-utils.h 2021-11-13 14:38:34.078700961 +0000
@@ -87,6 +87,7 @@
int nvidia_nvswitch_get_file_state(int minor);
int nvidia_cap_mknod(const char* cap_file_path, int *minor);
int nvidia_cap_get_file_state(const char* cap_file_path);
+int nvidia_cap_get_device_file_attrs(const char* cap_file_path, int *major, int *minor, char *name);
int nvidia_cap_imex_channel_mknod(int minor);
int nvidia_cap_imex_channel_file_state(int minor);
int nvidia_get_chardev_major(const char *name);
int nvidia_msr_modprobe(void);

View File

@@ -0,0 +1,181 @@
{
stdenv,
lib,
addDriverRunpath,
fetchFromGitHub,
pkg-config,
elfutils,
libcap,
libseccomp,
rpcsvc-proto,
libtirpc,
makeWrapper,
removeReferencesTo,
replaceVars,
applyPatches,
nvidia-modprobe,
go,
}:
let
modprobeVersion = "550.54.14";
patchedModprobe = applyPatches {
src = nvidia-modprobe.src.override {
version = modprobeVersion;
hash = "sha256-iBRMkvOXacs/llTtvc/ZC5i/q9gc8lMuUHxMbu8A+Kg=";
};
patches = [
(replaceVars ./modprobe.patch {
inherit modprobeVersion;
})
];
};
in
stdenv.mkDerivation (finalAttrs: {
pname = "libnvidia-container";
version = "1.17.8";
src = fetchFromGitHub {
owner = "NVIDIA";
repo = "libnvidia-container";
tag = "v${finalAttrs.version}";
hash = "sha256-OzjcYxnWjzgmrjERyPN3Ch3EQj4t1J5/TbATluoDESg=";
};
patches = [
# Locations of nvidia driver libraries are not resolved via ldconfig which
# doesn't get used on NixOS.
(replaceVars ./0001-ldcache-don-t-use-ldcache.patch {
inherit (addDriverRunpath) driverLink;
})
# Use both PATH and the legacy nvidia-docker paths (NixOS artifacts)
# for binary lookups.
# TODO: Remove the legacy compatibility once nvidia-docker is removed
# from NixOS.
(replaceVars ./0002-nvc-nvidia-docker-compatible-binary-lookups.patch {
inherit (addDriverRunpath) driverLink;
})
# fix bogus struct declaration
./0003-nvc-fix-struct-declaration.patch
];
postPatch = ''
sed -i \
-e 's/^REVISION ?=.*/REVISION = ${finalAttrs.src.tag}/' \
-e 's/^COMPILER :=.*/COMPILER = $(CC)/' \
mk/common.mk
sed -i \
-e 's/^GIT_TAG ?=.*/GIT_TAG = ${finalAttrs.version}/' \
-e 's/^GIT_COMMIT ?=.*/GIT_COMMIT = ${finalAttrs.src.tag}/' \
versions.mk
mkdir -p deps/src/nvidia-modprobe-${modprobeVersion}
cp -r ${patchedModprobe}/* deps/src/nvidia-modprobe-${modprobeVersion}
chmod -R u+w deps/src
pushd deps/src
touch nvidia-modprobe-${modprobeVersion}/.download_stamp
popd
# 1. replace DESTDIR=$(DEPS_DIR) with empty strings to prevent copying
# things into deps/src/nix/store
# 2. similarly, remove any paths prefixed with DEPS_DIR
# 3. prevent building static libraries because we don't build static
# libtirpc (for now)
# 4. prevent installation of static libraries because of step 3
# 5. prevent installation of libnvidia-container-go.so twice
# 6. Replace pkg-config and objcopy with target platform's one
# 7. Stub ldconfig
#
sed -i Makefile \
-e 's#DESTDIR=\$(DEPS_DIR)#DESTDIR=""#g' \
-e 's#\$(DEPS_DIR)\$#\$#g' \
-e 's#all: shared static tools#all: shared tools#g' \
-e '/$(INSTALL) -m 644 $(LIB_STATIC) $(DESTDIR)$(libdir)/d' \
-e '/$(INSTALL) -m 755 $(libdir)\/$(LIBGO_SHARED) $(DESTDIR)$(libdir)/d' \
-e "s,pkg-config,$PKG_CONFIG,g"
substituteInPlace mk/common.mk \
--replace-fail objcopy '$(OBJCOPY)' \
--replace-fail ldconfig true
'';
# Recreate library symlinks which ldconfig would have created
postFixup = ''
for lib in libnvidia-container libnvidia-container-go; do
rm -f "$out/lib/$lib.so"
ln -s "$out/lib/$lib.so.${finalAttrs.version}" "$out/lib/$lib.so.1"
ln -s "$out/lib/$lib.so.1" "$out/lib/$lib.so"
done
'';
enableParallelBuilding = true;
preBuild = ''
HOME="$(mktemp -d)"
'';
env = {
NIX_CFLAGS_COMPILE = toString [ "-I${lib.getInclude libtirpc}/include/tirpc" ];
CGO_ENABLED = "1"; # Needed for cross-compilation
GOFLAGS = "-trimpath"; # Don't include paths to Go stdlib to resulting binary
inherit (go) GOARCH GOOS;
};
NIX_LDFLAGS = [
"-L${lib.getLib libtirpc}/lib"
"-ltirpc"
];
nativeBuildInputs = [
pkg-config
go
rpcsvc-proto
makeWrapper
removeReferencesTo
];
buildInputs = [
elfutils
libcap
libseccomp
libtirpc
];
makeFlags = [
"WITH_LIBELF=yes"
"prefix=$(out)"
# we can't use the WITH_TIRPC=yes flag that exists in the Makefile for the
# same reason we patch out the static library use of libtirpc so we set the
# define in CFLAGS
"CFLAGS=-DWITH_TIRPC"
];
postInstall =
let
inherit (addDriverRunpath) driverLink;
libraryPath = lib.makeLibraryPath [
"$out"
driverLink
"${driverLink}-32"
];
in
''
remove-references-to -t "${go}" $out/lib/libnvidia-container-go.so.${finalAttrs.version}
wrapProgram $out/bin/nvidia-container-cli --prefix LD_LIBRARY_PATH : ${libraryPath}
'';
disallowedReferences = [ go ];
meta = {
homepage = "https://github.com/NVIDIA/libnvidia-container";
description = "NVIDIA container runtime library";
license = lib.licenses.asl20;
platforms = lib.platforms.linux;
mainProgram = "nvidia-container-cli";
maintainers = with lib.maintainers; [
cpcloud
msanft
katexochen
];
};
})