Running a Dynamically linked executable from a very picky programm

I need help trying to Package a program that is not in nixpkgs. I packaged It like this:

{ stdenv, lib, bash, perl, bison, flex, tcl, fltk, mesa, libGL, xorg, haskellPackages, cudaPackages, python3, python313Packages }:
    

stdenv.mkDerivation rec {

  pname = "vmd";
  version = "2.0.0";

  src = ./vmd-2.0.0.bin.LINUXAMD64.tar.gz;
  
  unpackPhase = ''
    tar -xvzf $src
    cp -r ${pname}-${version} source
    chmod -R +w source
    cd source
  '';

  nativeBuildInputs = [ bash perl bison flex cudaPackages.cudnn];

  patchPhase = ''
    patchShebangs configure

  '';

 preConfigure = ''

   substituteInPlace configure \
     --replace-fail 'install_bin_dir="usr/local/bin"' 'install_bin_dir="$out/bin"' \
     --replace-fail 'install_library_dir="/usr/local/lib/$install_name"' 'install_library_dir="$out/lib/vmd"'


 '';

  configurePhase = ''
    ./configure LINUX OPENGL FLTK MESA PYTHON NUMPY
  '';  



  dontBuild = true;

# recursion in symlinks solved. still broken bc other reasons.

  installPhase =''
    substituteInPlace src/config.h \
      --replace-fail "/lib/vmd" "$out/lib/vmd" \
      --replace-fail "/usr/local" "$out/local" 
   
    cat src/Makefile

    for f in src/Makefile bin/vmd.sh bin/vmd.csh  ; do
      substituteInPlace "$f" \
        --replace-fail "/usr/local/lib/vmd" "$out/lib/" \
        --replace-fail "/usr" "$out/usr" 
    done     
   
    cat src/Makefile   

    cd src
    make install 

    mkdir -p $out/bin
    mkdir -p $out/lib/vmd

    cd ..
    cp -r LINUXAMD64/* $out/bin
  '';

  propagatedBuildInputs = [
    tcl
    fltk
    mesa
    libGL
    xorg.libX11
    xorg.libXext
    xorg.libXi
    xorg.libXrender
    haskellPackages.OpenGL
    cudaPackages.cudnn
    python3
    python313Packages.numpy
];

  meta = with lib; {
    description = "Just for personal Use, has a complicated license";
    homepage = "https://www.ks.uiuc.edu/Research/vmd/";
    platforms = platforms.unix;
  };  
}

when running ./result/bin/vmd_LINUXAMD64 it says:

Could not start dynamically linked executable: ./result/bin/vmd_LINUXAMD64
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box.

How can I make it just run and include it to my configuration file?

Try autoPatchelfHook.

1 Like

autoPatchelfHook is fine but shouldn’t usually be required unless:

  • it’s not built from source
  • there’s some dependency on a library at runtime that is somehow not encoded during buildtime but still declared via DT_NEEDED

To rule out the former, are you sure you’re actually building the thing from source and not just copying in the prebuilt binary into $out/bin?

It’s actually okay to not build it from source (though it does preclude patching the program) - but in that case you might as well not waste the CPU cycles of configurePhase and buildPhase.

You also missed the pre/post-phase hooks, so some of that code isn’t even running :slight_smile:

You’ll need to correct anything that ends in Phase that you manually set.

There’s also other issues I see, but those are only really issues if you want to submit it to nixpkgs. You don’t have to do so.