Bulding GPAW on NixOS: issues with C++ toolchain

Hi all, I just started my adventure on NixOS and I am trying to get my environment up and running.
I am interested in installing GPAW on my system, I do not care too much about all the dependencies that can improve performance, so the list of dependencies reduces to:

  • Python 3.6 or later
  • NumPy 1.9 or later (base N-dimensional array package)
  • SciPy 0.14 or later (library for scientific computing)
  • ASE 3.18.0 or later (atomic simulation environment)
  • a C-compiler
  • LibXC 3.x or 4.x
  • BLAS library

I created shell.nix with the following content (based on an example on nixos.org):

{ pkgs ? import <nixpkgs> {} 
}:
pkgs.mkShell {                                
  name="dev-environment";                             
  buildInputs = [             
    pkgs.python3    
    pkgs.gcc
    pkgs.blas
    pkgs.libxc
   ]; 
   shellHook = ''                
     echo "Start developing..."  
   '';  
}

From the nix-shell I enter a Python venv I already created and then run pip install gpaw that installs the needed Python dependencies as well.
It actually complete the setup without any issue, but when I run gpaw test I obtain the following error:

[...]
plenty of stuff that redirects to the final error in a scipy function
[...]
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory

I am quite sure I am overlooking something obvious, but I cannot find the cause of this issue, probably because of my limited experience with NixOS.
Any hint is greatly appreciated!

1 Like

nixpkgs will only export glibc by default, libstdc++.so.6 is provided by gcc, not glibc.

  shellHook = ''
     LD_LIBRARY_PATH=${lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]};
  '';

you could also use gcc.cc.lib, but generally people will pull it out of stdenv to ensure library coherence in the case that cc provided by stdenv differs.

1 Like

Thank for the tip!
I tried but it did not find lib, so I modified it into:

   shellHook = ''             
     LD_LIBRARY_PATH=${pkgs.stdenv.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]}; 
     echo "Start developing..."                                                  
   '';

But it still returns the same error about libstdc++.so.6.

>>> echo $LD_LIBRARY_PATH
/nix/store/danv012gh0aakh8xnk2b35vahklz72mk-gcc-9.2.0-lib/lib

I solved the problem by using the Python packages provided by NixOS:

{ pkgs ? import <nixpkgs> {},
}:
pkgs.mkShell {                  
  name="dev-environment"; 
  buildInputs = [ 
    pkgs.python3    
    pkgs.python3Packages.numpy
    pkgs.python3Packages.scipy
    pkgs.python3Packages.matplotlib
    pkgs.python3Packages.six
    pkgs.python3Packages.pillow
    pkgs.python3Packages.kiwisolver
    pkgs.python3Packages.setuptools
    pkgs.python3Packages.wheel
    pkgs.python3Packages.pytest
    pkgs.python3Packages.spglib
    pkgs.python3Packages.flask
    pkgs.python3Packages.psycopg2
    pkgs.gcc
    pkgs.blas
    pkgs.libxc
    pkgs.openmpi
   ]; 
   shellHook = ''   
     echo "Activating Python venv..."
     source "$HOME/master-project/venv/bin/activate"
     export GPAW_SETUP_PATH="$HOME/master-project/gpaw-dataset/gpaw-setups-0.9.20000"
     export PYTHONPATH="$HOME/master-project/ase:$PYTHONPATH"
     export PATH="$HOME/master-project/ase/bin:$PATH"
     echo "Done."
   '';  
 }

The file contains some additional setup as well, just to set everything up in one step.
Maybe this is not a clean solution, but it works (finger crossed).

2 Likes