Hello,
I’m trying to write a derivation for a binary software that can (optionally I think) use CUDA. As far as I understand, the library libcuda.so
comes at runtime only, depending on your driver, in /run/opengl-drivers/
, and people (see blender project for example) seem to use addOpenGLRunpath
like that to automatically add at runtime a dependency to libraries in /run/opengl-drivers
:
postFixup = ''
for program in $out/bin/*; do
isELF "$program" || continue
addOpenGLRunpath "$program"
done
'';
Unfortunately, in my case the build fails even before, during the fixup
phase, where it tries to search dependencies:
automatically fixing dependencies for ELF files
searching for dependencies of /nix/store/9xv1xixw4h7x3w0z4rq1xv83vl7fgdcp-DaVinci_Resolve_16.2.7/BlackmagicRAWSpeedTest/BlackmagicRawAPI/libDecoderCUDA.so
libc++.so.1 -> found: /nix/store/9xv1xixw4h7x3w0z4rq1xv83vl7fgdcp-DaVinci_Resolve_16.2.7/BlackmagicRAWSpeedTest/lib/libc++.so.1
libc++abi.so.1 -> found: /nix/store/9xv1xixw4h7x3w0z4rq1xv83vl7fgdcp-DaVinci_Resolve_16.2.7/BlackmagicRAWSpeedTest/lib/libc++abi.so.1
libGL.so.1 -> found: /nix/store/avz5z36i6xmzvzzasqzq5j5xhbyzb1qd-libGL-1.2.0/lib/libGL.so.1
libcuda.so.1 -> not found!
libuuid.so.1 -> found: /nix/store/6fl90xarrf13vq63kyl47vqjz67n34ar-util-linux-2.33.2/lib/libuuid.so.1
The problem is that libcuda.so.1
does not exist at build time. I was thinking that adding cudatoolkit
to the buildInputs
would be enough to provide a dummy libcuda.so.1
to pass the fixup phase, but apparently it’s not enough
What is the solution to my problem? Is there a way to provide a dummy libcuda.so.1
at compilation time to pass the fixup phase? I don’t know if it matters, but on the build machine I may not have access to CUDA (and since CUDA should be optional, it may not even be present on the running machine I guess).
Thanks!
For reference, here is the file I’m using, trying to build DaVinci Resolve (free “normal” version). You can test it by simply downloading the .zip
file and putting it in the same folder as the following files:
derivation.nix
:
{ stdenv, mkDerivation, unzip, autoPatchelfHook, wrapQtAppsHook, libarchive, gtk2, qtbase, gstreamer, libpng12, ocl-icd, openssl, opencl-headers, alsaLib, libXtst, libXdamage, libGLU, cudatoolkit, addOpenGLRunpath }:
mkDerivation rec {
version = "16.2.7";
name = "DaVinci_Resolve_${version}";
src = ./DaVinci_Resolve_16.2.7_Linux.zip;
unpackPhase = ''
unzip $src
# Folder to extract the .run ISO image to
mkdir extracted
# bsdtar comes from libarchive
bsdtar x -f DaVinci_Resolve_${version}_Linux.run -C extracted
export sourceRoot=extracted
'';
nativeBuildInputs = [
unzip
libarchive
autoPatchelfHook
wrapQtAppsHook
addOpenGLRunpath
];
buildInputs = [
alsaLib
gtk2
gstreamer
libpng12
ocl-icd
openssl
qtbase
alsaLib
libXtst
libXdamage
libGLU
cudatoolkit
];
installPhase= ''
mkdir -p $out
cp -r * $out
'';
postFixup = ''
for program in $out/bin/*; do
isELF "$program" || continue
addOpenGLRunpath "$program"
done
'';
meta = {
description = "DaVinci Resolve";
homepage = https://;
license = stdenv.lib.licenses.unfree;
maintainers = [ stdenv.lib.maintainers.tobiasBora ];
platforms = stdenv.lib.platforms.linux;
};
}
default.nix
:
{ pkgs ? import <nixpkgs> {} }:
pkgs.libsForQt5.callPackage ./derivation.nix {}
– EDIT –
Maybe I can use the option autoPatchelfIgnoreMissingDeps = false;
but not sure it’s the best solution since it may miss other missing libraries.