Virtualgl server on NixOS

I need to use an OpenGL/GLFW program on a remote machine. x11vnc works for this, but performance is not great / I only need the one window not the full desktop.

The best solution I’ve found for this is VirtualGL: VirtualGL | About / A Brief Introduction to VirtualGL. There’s a very outdated nixpkg here: https://github.com/NixOS/nixpkgs/blob/437cc302b907663da827c00e8caf8750eca8aeb1/pkgs/tools/X11/virtualgl/default.nix.

To run as a server, the following script is executed for setup: https://github.com/VirtualGL/virtualgl/blob/e45af37e1bdc146e4076887b2505c3d5f1e86f87/server/vglserver_config. It modifies a number of different files in /etc, and comes in at over 1000 lines.

This feels like it should be a NixOS service, but I’m not even sure how to begin since it does so much mutation of /etc.

Any idea how I might go about this?

2 Likes

got it working! details here: virtualgl: 2.6.2 -> 2.6.5 by tbenst · Pull Request #105013 · NixOS/nixpkgs · GitHub

Edit: alas, I spoke prematurely… it does indeed work for simple demo apps like glxgears but doesn’t work for say vglrun julia. It seems the issue is nix-specific and I think is due to some conflict between how vglrun uses LD_PRELOAD, and how nix uses it… Any thoughts?

❯ vglrun bash -c 'echo $LD_PRELOAD'
[VGL] NOTICE: Automatically setting VGL_CLIENT environment variable to
[VGL]    128.12.176.76, the IP address of your SSH client.
/nix/store/wx4rf2zp434dgfin0c0n0b3g7c9f7r56-virtualgl-lib-2.6.5/lib/libdlfaker.so:/nix/store/wx4rf2zp434dgfin0c0n0b3g7c9f7r56-virtualgl-lib-2.6.5/lib/libvglfaker.so
❯ vglrun +v +tr julia
[VGL] NOTICE: Automatically setting VGL_CLIENT environment variable to
[VGL]    128.12.176.76, the IP address of your SSH client.
[VGL] dlopen (filename=/nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 flag=2 retval=0x7f17533ca5c0)
[VGL] dlopen (filename=NULL flag=2 retval=0x7f1753400130)
[VGL] dlopen (filename=/nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so flag=2 retval=0x01209800)
[VGL] dlopen (filename=NULL flag=257 retval=0x7f1753400130)
[VGL] dlopen (filename=libpcre2-8 flag=9 retval=0x00000000)
[VGL] dlopen (filename=libpcre2-8.so flag=9 retval=0x00000000)
fatal: error thrown and no exception handler available.
#<null>
jl_errorf at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jl_load_dynamic_library at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jl_get_library_.part.0 at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jl_load_and_lookup at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jlplt_pcre2_compile_8_7047 at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
compile at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
compile at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
normpath at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
abspath at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
abspath at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
__init__ at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
jfptr___init___46815 at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
jl_module_run_initializer at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
_julia_init at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
main at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/julia (unknown line)
__libc_start_main at /nix/store/9df65igwjmf2wbw0gbrrgair6piqjgmi-glibc-2.31/lib/libc.so.6 (unknown line)
_start at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/julia (unknown line)

Edit 2: seems this error has nothing to do with virtualgl but is instead a Nix/Julia error (doesn’t happen on non-nix julia):

❯ export LD_PRELOAD="/nix/store/wx4rf2zp434dgfin0c0n0b3g7c9f7r56-virtualgl-lib-2.6.5/lib/libdlfaker.so:/nix/store/wx4rf2zp434dgfin0c0n0b3g7c9f7r56-virtualgl-lib-2.6.5/lib/libvglfaker.so"
❯ julia
fatal: error thrown and no exception handler available.
#<null>
jl_errorf at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jl_load_dynamic_library at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jl_get_library_.part.0 at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jl_load_and_lookup at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
jlplt_pcre2_compile_8_7047 at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
compile at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
compile at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
normpath at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
abspath at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
abspath at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
__init__ at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
jfptr___init___46815 at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/lib/julia/sys.so (unknown line)
jl_module_run_initializer at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
_julia_init at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/../lib/libjulia.so.1 (unknown line)
main at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/julia (unknown line)
__libc_start_main at /nix/store/9df65igwjmf2wbw0gbrrgair6piqjgmi-glibc-2.31/lib/libc.so.6 (unknown line)
_start at /nix/store/lqyhf3ympk18f41prmhaxd450xpmp8h9-julia-1.5.2/bin/julia (unknown line)

@cstich do you have any ideas by chance? Saw you added this comment in julia derivation:

# Symlink shared libraries from LD_LIBRARY_PATH into lib/julia,
# as using a wrapper with LD_LIBRARY_PATH causes segmentation
# faults when program returns an error:
#   $ julia -e 'throw(Error())'

I think I’m seeing a segfault related to LD_PRELOAD, but am a bit confused as to what is causing this since I don’t see the same Julia behavior on ubuntu. Appreciate any thoughts!

Sorry for the late reply. I missed this one. I don’t really remember why exactly I wrote this comment/ I am not sure I wrote it in the first place. Sorry for not being more helpful.