Nvfortran pass a directory as link script to ld, causing ld failed

I am trying to port nvhpc-sdk to NixOS, however, nvfortran does not work (ld error while compiling a simple “hello world” fortran program). The reason is, nvfortran passed a directory to ld as a link script, then ld complains read in flex scanner failed. Could anyone please help me figure out, why nvhpc always pass this directory to ld?

Here is the log. nvfortran first call fort1, then fort2, then llc and append, these calls are all success. Finally it calls ld and failed.

hdf5-fortran> -- Check for working Fortran compiler: /nix/store/slyw83jlrp6vyjwyqxvka8wvkr6893mz-nvhpc-wrapper-24.11/bin/nvfortran
hdf5-fortran> -- Check for working Fortran compiler: /nix/store/slyw83jlrp6vyjwyqxvka8wvkr6893mz-nvhpc-wrapper-24.11/bin/nvfortran - broken
hdf5-fortran> CMake Error at /nix/store/7yhxinagh4i7q1kw9fn7mdz4bcjakcy9-cmake-3.30.5/share/cmake-3.30/Modules/CMakeTestFortranCompiler.cmake:59 (message):
hdf5-fortran>   The Fortran compiler
hdf5-fortran>
hdf5-fortran>     "/nix/store/slyw83jlrp6vyjwyqxvka8wvkr6893mz-nvhpc-wrapper-24.11/bin/nvfortran"
hdf5-fortran>
hdf5-fortran>   is not able to compile a simple test program.
hdf5-fortran>
hdf5-fortran>   It fails with the following output:
hdf5-fortran>
hdf5-fortran>     Change Dir: '/build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw'
hdf5-fortran>
hdf5-fortran>     Run Build Command(s): /nix/store/7yhxinagh4i7q1kw9fn7mdz4bcjakcy9-cmake-3.30.5/bin/cmake -E env VERBOSE=1 /nix/store/2bmv1q22qv2a1zns2jjhwyabddb4vaqv-gnumake-4.4.1/bin/make -f Makefile cmTC_48388/fast
hdf5-fortran>     /nix/store/2bmv1q22qv2a1zns2jjhwyabddb4vaqv-gnumake-4.4.1/bin/make  -f CMakeFiles/cmTC_48388.dir/build.make CMakeFiles/cmTC_48388.dir/build
hdf5-fortran>     make[1]: Entering directory '/build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw'
hdf5-fortran>     Building Fortran object CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o
hdf5-fortran>     /nix/store/slyw83jlrp6vyjwyqxvka8wvkr6893mz-nvhpc-wrapper-24.11/bin/nvfortran   -fPIE -c /build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw/testFortranCompiler.f -o CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o
hdf5-fortran>     nvfortran-Warning-Unknown switch: -B/nix/store/89w3fyyzmif5kjjjnhqmyavg9fniljd3-glibc-2.40-36/lib/
hdf5-fortran>     nvfortran-Warning-Unknown switch: -idirafter
hdf5-fortran>     nvfortran-Warning-Unknown switch: -B/nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/lib
hdf5-fortran>     nvfortran-Warning-Unknown switch: -B/nix/store/qxz7l1jv1kj8548dld4qyaa9ddfw18sz-binutils-wrapper-2.43.1/bin/
hdf5-fortran>     nvfortran-Warning-Unknown switch: -frandom-seed=mi5d914g7q
hdf5-fortran>     nvfortran-Warning-The -gpu option has no effect unless a language-specific option to enable GPU code generation is used (e.g.: -acc, -mp=gpu, -stdpar, -cuda)
hdf5-fortran>     /build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw/testFortranCompiler.f:
hdf5-fortran>
hdf5-fortran>     /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/bin/tools/fort1 /build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw/testFortranCompiler.f -opt 1 -nostatic -x 19 0x400000 -quad -x 59 4 -x 15 2 -x 49 0x400004 -x 51 0x20 -x 57 0x4c -x 58 0x10000 -x 124 0x1000 -tp znver4 -x 57 0xfb0000 -x 58 0x78031040 -x 47 0x08 -x 48 4608 -x 49 0x100 -stdinc /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/include:/nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/include-stdexec:/nix/store/0dynnad751nnm3bczxscvc50sdmp867v-dpkg-1.22.10/include:/nix/store/icsq0mbjhzfmjw1asm7v2556k3822z4r-glibc-multi-2.40-36-dev/include:/nix/store/r2c59ahksdblhnaqrn24yp6kcs7di2m2-libz-1.2.8.2015.12.26-unstable-2018-03-31-dev/include:/nix/store/49v6ljxl1h5i22iw90bhx56p31nipas3-libxml2-2.13.4-dev/include:/nix/store/wr7935gmcwn1626h26qh024w85dxq280-zstd-1.5.6-dev/include:/nix/store/lzf45yqida6l8bqf5isz7wfllwlg2jv1-numactl-2.0.18-dev/include:/nix/store/pk11q25n9bmn5jz294zcrnw0429py0gy-ncurses-6.4.20221231-dev/include:/nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/include:/nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include:/nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/include-fixed:/nix/store/axv588igjrlrbxhw1k2mh943dydb6q78-glibc-2.40-36-dev/include:/nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include:/nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include -cmdline '+nvfortran /build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw/testFortranCompiler.f -tp=znver4 -gpu=cc89 -# -fPIE -pie -c -o CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o -# -noswitcherror -isystem /nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include -isystem /nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include' -def __unix -def __unix__ -def unix -def linux -def __linux -def __linux__ -def __ELF__ -def __NO_MATH_INLINES -def __LP64__ -def __x86_64 -def __x86_64__ -def __LONG_MAX__=9223372036854775807L -def '__SIZE_TYPE__=unsigned long int' -def '__PTRDIFF_TYPE__=long int' -def __amd64 -def __amd64__ -def __k8 -def __k8__ -def __MMX__ -def __SSE_MATH__ -def __MMX_WITH_SSE__ -def __SSE__ -def __SSE2__ -def __SSE2_MATH__ -def __SSE3__ -def __SSSE3__ -def __SSE4A__ -def __SSE4_1__ -def __SSE4_2__ -def __ABM__ -def __ADX__ -def __AES__ -def __AVX__ -def __AVX2__ -def __AVX512BF16__ -def __AVX512BITALG__ -def __AVX512BW__ -def __AVX512CD__ -def __AVX512DQ__ -def __AVX512F__ -def __AVX512IFMA__ -def __AVX512VBMI__ -def __AVX512VBMI2__ -def __AVX512VL__ -def __AVX512VNNI__ -def __AVX512VPOPCNTDQ__ -def __BMI__ -def __BMI2__ -def __CLFLUSHOPT__ -def __CLWB__ -def __CLZERO__ -def __F16C__ -def __FMA__ -def __FSGSBASE__ -def __FXSR__ -def __GFNI__ -def __LZCNT__ -def __MOVBE__ -def __MWAITX__ -def __PCLMUL__ -def __PKU__ -def __POPCNT__ -def __PRFCHW__ -def __RDPID__ -def __RDRND__ -def __RDSEED__ -def __LAHF_SAHF__ -def __SHA__ -def __VAES__ -def __VPCLMULQDQ__ -def __WBNOINVD__ -def __XSAVE__ -def __XSAVEC__ -def __XSAVEOPT__ -def __XSAVES__ -idir /nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include -idir /nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include -def __PGLLVM__ -def __NVCOMPILER_LLVM__ -def __extension__= -def __NVCOMPILER_GPU_SEPARATE_MEM -def __PIC__ -def __PIE__ -def __PIC__ -def __PIE__ -nofreeform -vect 48 -x 54 1 -mach 0 -nomach 0 -x 68 0x1 -x 70 0x40000000 -x 70 0x40000000 -x 68 0x1 -x 124 1 -x 195 0x8000 -y 163 0xc0000000 -x 189 0x10 -stbfile /build/nvfortranw-cbcHx8CnYf.stb -modexport /build/nvfortrang-cbsPtcruoB.cmod -modindex /build/nvfortran2-cbIZWpA1MN.cmdx -cci /build/nvfortranM-cbYkMmqogs.cci -output /build/nvfortran2-cbIwlyNTwX.ilm
hdf5-fortran>       0 inform,   0 warnings,   0 severes, 0 fatal for testfortran
hdf5-fortran>     NVFORTRAN/x86-64 Linux 24.11-0: compilation successful
hdf5-fortran>
hdf5-fortran>     /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/bin/tools/fort2 /build/nvfortran2-cbIwlyNTwX.ilm -fn /build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw/testFortranCompiler.f -opt 1 -x 51 0x20 -x 119 0xa10000 -x 122 0x40 -x 123 0x1000 -x 127 4 -x 127 17 -x 19 0x400000 -x 28 0x40000 -x 120 0x10000000 -x 70 0x8000 -x 122 1 -x 125 0x20000 -quad -x 59 4 -tp znver4 -x 120 0x1000 -x 124 0x1400 -y 15 2 -x 57 0x3b0000 -x 58 0x48000000 -x 49 0x100 -astype 0 -x 121 1 -x 183 4 -x 121 0x800 -mach 0 -nomach 0 -x 68 0x1 -x 8 0x40000000 -x 70 0x40000000 -x 56 0x10 -x 54 0x10 -x 249 170 -x 68 0x20 -x 70 0x40000000 -x 8 0x40000000 -x 164 0x800000 -x 71 0x2000 -x 71 0x4000 -x 34 0x40000000 -x 120 0x1000000 -x 73 0x04 -x 231 0x800 -x 68 0x1 -x 39 4 -x 56 0x10 -x 26 0x10 -x 26 1 -x 56 0x4000 -x 124 1 -x 197 0 -x 175 0 -x 203 0 -x 204 0 -x 227 0xFFFF -y 163 0xc0000000 -x 189 0x10 -y 189 0x4000000 -x 60 512 -x 62 8 -x 62 8 -cci /build/nvfortranM-cbYkMmqogs.cci -cmdline '+nvfortran /build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw/testFortranCompiler.f -tp=znver4 -gpu=cc89 -# -fPIE -pie -c -o CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o -# -noswitcherror -isystem /nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include -isystem /nix/store/vp90z3pv4k9d1ra7b5j0rvm072igncx4-zlib-1.3.1-dev/include' -stbfile /build/nvfortranw-cbcHx8CnYf.stb -asm /build/nvfortranw-cbcoXsGUNy.ll
hdf5-fortran>       0 inform,   0 warnings,   0 severes, 0 fatal for testfortran
hdf5-fortran>     NVFORTRAN/x86-64 Linux 24.11-0: compilation successful
hdf5-fortran>
hdf5-fortran>     /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/share/llvm/bin/llc /build/nvfortranw-cbcoXsGUNy.ll -march=x86-64 -mcpu=znver4 -mattr=+mmx -mattr=+sse -mattr=+sse2 -mattr=+sse3 -mattr=+ssse3 -mattr=+sse4a -mattr=+sse4.1 -mattr=+sse4.2 -mattr=+avx -mattr=+avx2 -mattr=+avx512f -mattr=+avx512cd -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -mattr=+avx512ifma -mattr=+avx512vbmi -mattr=+avx512vbmi2 -mattr=+avx512bitalg -mattr=+avx512vpopcntdq -mattr=+avx512vnni -mattr=+f16c -mattr=+fma -mattr=+xsave -mattr=+xsaveopt -mattr=+xsavec -mattr=+xsaves -mattr=+popcnt -mattr=+sha -mattr=+aes -mattr=+pclmul -mattr=+clflushopt -mattr=+fsgsbase -mattr=+rdrnd -mattr=+bmi -mattr=+bmi2 -mattr=+lzcnt -mattr=+fxsr -mattr=+mwaitx -mattr=+clzero -mattr=+pku -mattr=+gfni -mattr=+vaes -mattr=+vpclmulqdq -mattr=+adx -mattr=+avx512bf16 -mattr=+clwb -mattr=+movbe -mattr=+prfchw -mattr=+rdpid -mattr=+rdseed -mattr=+sahf -mattr=+wbnoinvd -O1 -x86-cmov-converter=0 -dwarf-directory=false -non-global-value-max-name-size=4294967295 --align-all-functions=6 -nvhpc-memzero -relocation-model=pic -filetype=obj --frame-pointer=none -o CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o
hdf5-fortran>
hdf5-fortran>     /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/bin/tools/append -noerror CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o -name .IPDINFO /build/nvfortrang-cbsPtcruoB.cmod -name .IPEINFO /build/nvfortran2-cbIZWpA1MN.cmdx
hdf5-fortran>     Linking Fortran executable cmTC_48388
hdf5-fortran>     /nix/store/7yhxinagh4i7q1kw9fn7mdz4bcjakcy9-cmake-3.30.5/bin/cmake -E cmake_link_script CMakeFiles/cmTC_48388.dir/link.txt --verbose=1
hdf5-fortran>     /nix/store/slyw83jlrp6vyjwyqxvka8wvkr6893mz-nvhpc-wrapper-24.11/bin/nvfortran CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o -o cmTC_48388
hdf5-fortran>     nvfortran-Warning-Unknown switch: -B/nix/store/89w3fyyzmif5kjjjnhqmyavg9fniljd3-glibc-2.40-36/lib/
hdf5-fortran>     nvfortran-Warning-Unknown switch: -idirafter
hdf5-fortran>     nvfortran-Warning-Unknown switch: -B/nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/lib
hdf5-fortran>     nvfortran-Warning-Unknown switch: -B/nix/store/qxz7l1jv1kj8548dld4qyaa9ddfw18sz-binutils-wrapper-2.43.1/bin/
hdf5-fortran>     nvfortran-Warning-Unknown switch: -frandom-seed=mi5d914g7q
hdf5-fortran>     nvfortran-Warning-The -gpu option has no effect unless a language-specific option to enable GPU code generation is used (e.g.: -acc, -mp=gpu, -stdpar, -cuda)
hdf5-fortran>
hdf5-fortran>     /nix/store/fxk79n9111mmlj4lpyas8lfivfj9ridj-gfortran-wrapper-13.3.0/bin/ld /nix/store/5x5mdv676x7qxc3vp6nyrinv52g6h9mc-glibc-multi-2.40-36/lib/crt1.o /nix/store/5x5mdv676x7qxc3vp6nyrinv52g6h9mc-glibc-multi-2.40-36/lib/crti.o /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0//crtbegin.o /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/lib/f90main.o --eh-frame-hdr -m elf_x86_64 -dynamic-linker /nix/store/89w3fyyzmif5kjjjnhqmyavg9fniljd3-glibc-2.40-36/lib64/ld-linux-x86-64.so.2 -T /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/lib/nvhpc.ld -L/nix/store/i1r25z2pfsiqwbvhqw75l4hd9yvm5j6r-zlib-1.3.1/lib -L/nix/store/i1r25z2pfsiqwbvhqw75l4hd9yvm5j6r-zlib-1.3.1/lib -L/nix/store/i1r25z2pfsiqwbvhqw75l4hd9yvm5j6r-zlib-1.3.1/lib -L/nix/store/89w3fyyzmif5kjjjnhqmyavg9fniljd3-glibc-2.40-36/lib -L/nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/lib -L/nix/store/qagmkpkfy4kviil6winzxz7kx443kr4y-gcc-13.3.0-lib/lib -L/nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/lib -L/nix/store/5x5mdv676x7qxc3vp6nyrinv52g6h9mc-glibc-multi-2.40-36/lib -L/nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/ -dynamic-linker=/nix/store/89w3fyyzmif5kjjjnhqmyavg9fniljd3-glibc-2.40-36/lib/ld-linux-x86-64.so.2 CMakeFiles/cmTC_48388.dir/testFortranCompiler.f.o /nix/store/axv588igjrlrbxhw1k2mh943dydb6q78-glibc-2.40-36-dev/include -rpath /nix/store/mi5d914g7qg8asah7mb98rc9r9y7hx8j-hdf5-fortran-1.14.5/lib -rpath /nix/store/8sp3373my4lnvcsn9l1b18q45mwn11zb-nvhpc-24.11/opt/nvidia/hpc_sdk/Linux_x86_64/24.11/compilers/lib -rpath /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0//../../../../lib64 -o cmTC_48388 -L/nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0//../../../../lib64 -lnvf -lnvomp -ldl --as-needed -lnvhpcatm -latomic --no-as-needed -lpthread -lnvcpumath -lnsnvc -lnvc -lrt -lpthread -lgcc -lc -lgcc_s -lm /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0//crtend.o /nix/store/5x5mdv676x7qxc3vp6nyrinv52g6h9mc-glibc-multi-2.40-36/lib/crtn.o
hdf5-fortran>     /nix/store/pg61jb4gf8wdrskinznhk9sn6sgb0xln-binutils-2.43.1/bin/ld: read in flex scanner failed
hdf5-fortran>     nvfortran-Fatal-linker completed with exit code 1
hdf5-fortran>
hdf5-fortran>     make[1]: *** [CMakeFiles/cmTC_48388.dir/build.make:99: cmTC_48388] Error 2
hdf5-fortran>     make[1]: Leaving directory '/build/source/build/CMakeFiles/CMakeScratch/TryCompile-eBSskw'
hdf5-fortran>     make: *** [Makefile:127: cmTC_48388/fast] Error 2
hdf5-fortran>
hdf5-fortran>
hdf5-fortran>
hdf5-fortran>
hdf5-fortran>
hdf5-fortran>   CMake will not be able to correctly generate this project.
hdf5-fortran> Call Stack (most recent call first):
hdf5-fortran>   config/cmake/HDFUseFortran.cmake:16 (enable_language)
hdf5-fortran>   config/cmake/HDF5UseFortran.cmake:17 (include)
hdf5-fortran>   CMakeLists.txt:1115 (include)
hdf5-fortran>
hdf5-fortran>
hdf5-fortran> -- Configuring incomplete, errors occurred!

Here is my localrc:

set LDSO=/nix/store/89w3fyyzmif5kjjjnhqmyavg9fniljd3-glibc-2.40-36/lib64/ld-linux-x86-64.so.2;
set GCCDIR=/nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/;
set OEM_INFO=64-bit target on x86-64 Linux $INFOTPVAL;
set GNUATOMIC=-latomic;
set GCCINC=/nix/store/0dynnad751nnm3bczxscvc50sdmp867v-dpkg-1.22.10/include /nix/store/icsq0mbjhzfmjw1asm7v2556k3822z4r-glibc-multi-2.40-36-dev/include /nix/store/r2c59ahksdblhnaqrn24yp6kcs7di2m2-libz-1.2.8.2015.12.26-unstable-2018-03-31-dev/include /nix/store/49v6ljxl1h5i22iw90bhx56p31nipas3-libxml2-2.13.4-dev/include /nix/store/wr7935gmcwn1626h26qh024w85dxq280-zstd-1.5.6-dev/include /nix/store/lzf45yqida6l8bqf5isz7wfllwlg2jv1-numactl-2.0.18-dev/include /nix/store/pk11q25n9bmn5jz294zcrnw0429py0gy-ncurses-6.4.20221231-dev/include /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/include /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/include-fixed /nix/store/axv588igjrlrbxhw1k2mh943dydb6q78-glibc-2.40-36-dev/include;
set GPPDIR=/nix/store/0dynnad751nnm3bczxscvc50sdmp867v-dpkg-1.22.10/include /nix/store/icsq0mbjhzfmjw1asm7v2556k3822z4r-glibc-multi-2.40-36-dev/include /nix/store/r2c59ahksdblhnaqrn24yp6kcs7di2m2-libz-1.2.8.2015.12.26-unstable-2018-03-31-dev/include /nix/store/49v6ljxl1h5i22iw90bhx56p31nipas3-libxml2-2.13.4-dev/include /nix/store/wr7935gmcwn1626h26qh024w85dxq280-zstd-1.5.6-dev/include /nix/store/lzf45yqida6l8bqf5isz7wfllwlg2jv1-numactl-2.0.18-dev/include /nix/store/pk11q25n9bmn5jz294zcrnw0429py0gy-ncurses-6.4.20221231-dev/include /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include/c++/13.3.0/ /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include/c++/13.3.0//x86_64-unknown-linux-gnu /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include/c++/13.3.0//backward /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/include /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/include /nix/store/605hgp0v6rf9945vmvz2pizz069h5bvc-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-gnu/13.3.0/include-fixed /nix/store/axv588igjrlrbxhw1k2mh943dydb6q78-glibc-2.40-36-dev/include;
set NUMALIBNAME=-lnuma;
set LOCALRC=YES;
set EXTENSION=__extension__=;
set LC=-lgcc -lc $if(-Bstatic,-lgcc_eh, -lgcc_s);
# GLIBC version 2.40
# GCC version 13.3.0
set GCCVERSION=130300;
set LIBNCURSES=YES;
export PGI=$COMPBASE;

Additionally, I passed the following content through NVLOCALRC:

set DEFLIBDIR=/nix/store/5x5mdv676x7qxc3vp6nyrinv52g6h9mc-glibc-multi-2.40-36/lib;
set DEFSTDOBJDIR=/nix/store/5x5mdv676x7qxc3vp6nyrinv52g6h9mc-glibc-multi-2.40-36/lib;

I found the reason.
Nix passed the following flag to ld:

-idirafter /nix/store/axv588igjrlrbxhw1k2mh943dydb6q78-glibc-2.40-36-dev/include

-idirafter is not recognized by nvfortran and ignored by nvfortran, but /nix/store/axv588igjrlrbxhw1k2mh943dydb6q78-glibc-2.40-36-dev/include was preserved by nvfortran and passed to ld.