System with NixOS: how to add another extra distribution

@sean-bennett112 Looks like GR depends on a few Qt libraries, which you will need to add to the extraLibs list.

You should be able to do nix-locate -1 -w foo.so.4 to find which nix package provides the shared library. For a bit more context see the relevant section in the Nixos wiki.

Edit: Grammar

@cstich Thanks for the nix-locate pointer, that’s incredibly useful!

After doing that, looks like things still don’t work. After some poking around, it looks like this is due to the interpreter being incorrect.

āÆ readelf -l ~/.julia/packages/GR/tPkHV/deps/gr/bin/gksqt | grep Requesting
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

As you can see, it’s expecting an interpreter at /lib64/ld-linux-x86-64.so.2 which does not exist on NixOS. I’ve confirmed that manually patching the binary(after running Pkg.add("GR"))via the below command does resolve the issue.

patchelf --set-interpreter "(cat $NIX_CC/nix-support/dynamic-linker)" ~/.julia/packages/GR/tPkHV/deps/gr/bin/gksqt

For GR specifically, you can see in build.jl that we can pass in an environment variable GRDIR to use a pre-existing copy of gksqt. From a cursory glance through nixpkgs, it looks like GR framework isn’t packaged yet. That’s a solvable problem, though.

However I’m not sure if there exists a more general solution for when Julia packages download pre-built binaries. Maybe this is something the move towards BinaryProvider will help address?

In any case, thanks for pointing me in the right direction!

If someone else eventually needs to patch the gksqt binary. Here is how you do it semi-automatically within a nix expression:

let 
 libPath = lib.makeLibraryPath [
    qt4 
    gcc9 
    stdenv.cc.cc.lib
  ];

in

  pkgs.stdenv.mkDerivation {
  name = "sandbox-julia";
  buildInputs = with pkgs; [
    julia
  ];
  shellHook = ''
    # Make sure the GR package is installed in the current project
    julia -e 'using Pkg; Pkg.activate("./"); Pkg.add("GR")'

  # Patch the GKS binary for GR
     patchelf \
     --set-interpreter ${glibc}/lib/ld-linux-x86-64.so.2 \
     --set-rpath "${libPath}" \
     /home/user/.julia/packages/GR/cRdXQ/deps/gr/bin/gksqt
'';
}

3 Likes