I am trying to package NVHPC-SDK, which is a priority compiler from NVIDIA. But I could not figure out how to add additional item to PATH environment variable in stdenv. Could anyone please help me?
I packaged it with the following steps:
- Unpack source, patch elf, etc. Then I get nvhpc.
nvhpc = stdenv.mkDerivation
{
pname = "nvhpc";
inherit (src) src version;
buildInputs =
[
libz libxml2 zstd numactl ncurses openssl gmp openssl_1_1 libxcrypt-legacy libfabric rdma-core gfortran.cc.lib
xorg.libpciaccess
];
nativeBuildInputs = [ autoPatchelfHook dpkg flock ];
langFortran = true;
dontConfigure = true;
dontBuild = true;
installPhase =
''
mkdir -p $out
sed -i 's|/bin/chmod|chmod|g' install_components/install
sed -i 's|/sbin/ldconfig|ldconfig|g' install_components/install
patchShebangs install_components/Linux_x86_64/${src.version}/compilers/bin/makelocalrc
sed -i '/makelocalrc executed by/d' install_components/Linux_x86_64/${src.version}/compilers/bin/makelocalrc
NVHPC_SILENT=true NVHPC_INSTALL_DIR=$out NVHPC_INSTALL_TYPE=single ./install_components/install
addAutoPatchelfSearchPath $out/Linux_x86_64/${src.version}/cuda/${src.cudaVersion}/targets/x86_64-linux/lib/stubs
rm -rf $out/Linux_x86_64/${src.version}/cuda/${src.cudaVersion}/bin/cuda-gdb-python*-tui
rm -rf $out/Linux_x86_64/${src.version}/profilers
'';
autoPatchelfIgnoreMissingDeps = [ "libgdrapi.so.2" "libxpmem.so.0" "libnvidia-ml.so.1" ];
};
- Wrap
nvhpc
to getnvhpc-wrapped
:
wrapper = (wrapCCWith
{
cc = nvhpc;
extraBuildCommands =
''
echo "-L${gcc}/lib" >> $out/nix-support/cc-ldflags
echo "-tp=${config.nvhpcArch}" >> $out/nix-support/cc-cflags-before
echo "-gpu=${cudaCapability}" >> $out/nix-support/cc-cflags-before
echo "-noswitcherror" >> $out/nix-support/cc-cflags
# >> $out/nix-support/setup-hook << EOF
# addNvhpcEnv() {
# addToSearchPath PATH ${nvhpc}/Linux_x86_64/${nvhpc.version}/compilers/bin
# addToSearchPath PATH ${nvhpc}/Linux_x86_64/${nvhpc.version}/comm_libs/mpi/bin
# }
# addEnvHooks "$hostOffset" addNvhpcEnv
# EOF
# print verbose output for debugging
# echo "-v" >> $out/nix-support/cc-cflags
# echo "" > $out/nix-support/add-hardening.sh
# substitute -idirafter in libc-cflags
# somehow -isystem does not work
sed -i 's/-idirafter/-I/g' $out/nix-support/libc-cflags
for i in nvc nvc++ nvcc nvfortran; do
wrap $i $wrapper ${nvhpc}/Linux_x86_64/${nvhpc.version}/compilers/bin/$i
done
'';
}).overrideAttrs (prev: { installPhase = prev.installPhase +
''
export named_cc=nvc
export named_cxx=nvc++
export named_fc=nvfortran
'';});
- Override compiler in
stdenv
to getnvhpcStdenv
:
addAttrsToDerivation { NVLOCALRC = customLocalrc; } (overrideCC stdenv wrapper)
I try to set environment using ${wrapper}/nix-support/setup-hook
(commented code above), but it does not work. Could anyone tell me what is the correct way to add custom directory ${nvhpc}/Linux_x86_64/${nvhpc.version}/comm_libs/mpi/bin
into PATH in nvhpcStdenv
?