Nim/Arraymancer libopenblas.so: cannot open shared object file: No such file or directory

I am trying to use Nimlang and the Arraymancer library for some ML models but when I try to compile the program I get the following error:

nim compile -r -d:nimDebugDlOpen -d:blas=openblas -d:lapack=openblas main.nim

Hint: used config file '/nix/store/k0apz12k1a4j1yp21qm8wn5amdn80p4a-x86_64-unknown-linux-gnu-nim-wrapper-2.0.8/etc/nim/nim.cfg' [Conf]
Hint: used config file '/nix/store/k0apz12k1a4j1yp21qm8wn5amdn80p4a-x86_64-unknown-linux-gnu-nim-wrapper-2.0.8/etc/nim/config.nims' [Conf]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
24014 lines; 0.083s; 37.633MiB peakmem; proj: /home/name/Projects/project/main.nim; out: /home/name/Projects/project/main [SuccessX]
Hint: /home/name/Projects/project/main [Exec]
libopenblas.so: cannot open shared object file: No such file or directory
libopenblas.so.3: cannot open shared object file: No such file or directory
libopenblas.so.2: cannot open shared object file: No such file or directory
libopenblas.so.1: cannot open shared object file: No such file or directory
libopenblas.so.0: cannot open shared object file: No such file or directory
could not load: libopenblas.so(|.3|.2|.1|.0)
Error: execution of an external program failed: '/home/name/Projects/project/main'

I tried looking around and found that a possible solution could be an overlay so I made blas.nix

self: super: {
  blas = super.blas.override {
    blasProvider = self.openblas;
  };

  lapack = super.lapack.override {
    lapackProvider = self.openblas;
  };
}

and imported it to my config, but I still get the same error.

You probably need to use nix to make that shared object file available at compile time. Perhaps using the buildInputs attribute of stdenv.mkDerivation. There may be some nim specific tooling in nixpkgs, or not. I never looked into that. See the nixpkgs reference manual.

By config do you mean a system configuration or a project configuration?

As @mightiam mentioned on NixOS you’ll need the shared libraries themselves to be available at compile time.

You could do this using a devShell or by making a derivation.

For nim packages there is buildNimPackage that may be the easiest to get started with. In which, you can add openblas as a buildInput and then compile with nix directly.

For example, in this package I made to make lock files consumable by buildNimPackage. I needed access to the openssl shared libraries so I added it to the buildInputs and compile it with nix build.