Any way to make some runtime dependencies available system-wide?

Some build tools produce executables that depends on some libraries (like libX11.so.6), and they are listed as not found in ldd, so I get an error when I run them.
I know I can create a nix-shell

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    # nativeBuildInputs is usually what you want -- tools you need to run
    nativeBuildInputs = with pkgs.buildPackages; [ 
      xorg.libX11
    ];
}

but sometimes those executables are not called directly by me (for example: vscode extension for zig uses zls to build a project, only to get a linker error because some package links to system library - so I don’t get completions).

Is there any way to list some packages in configuration.nix to always be available?

I also tried this, but it didn’t work (while creating a shell did)

  programs.nix-ld.enable = true;
  programs.nix-ld.libraries = with pkgs; [
    pkgs.xorg.libX11
  ];

If you’re using zig, as with any development setup, you should already be in a development shell. So you should also add zls to said shell.

Such packages do not go in your config.

https://nix.dev/tutorials/first-steps/declarative-shell#declarative-reproducible-envs

1 Like

vscode extension automaticly tries to build the project so I get completion for dependencies. I don’t really want to launch vscode from development shell every time, + I was hoping to get universal solution, since vscode will probably not be the only thing that tries to link system library, or depend on system library.

Then use plugins that load the environment from nix, there are plenty of them, and all of them suffer from the fact that they can’t influence loading order and are therefore prone to races.

If there are other programs causing problems, then that is usually because of bad packaging on their side and needs to be fixed.

There is no global solution to this by design of nix.