Build works in nix-shell but not default shell even though same packages should be present

To build my rust project I need openssl and pkg-config so I added them to my configuration.nix. Even though I did that, the build still only works if I run nix-shell -p openssl pkg-config before building. How can that be?

pkg-config has a setup hook that configures environment variables to let libraries be found. These do not get set by NixOS - only by the standard environment.

NixOS has no concept of system-wide libraries*. What use is there for a system-wide library directory when packages are designed to refer to specific Nix store paths? environment.systemPackages only concerns paths that have some sort of system-wide significance. How does pkg-config know where to find OpenSSL?

*With the exception of GPU API drivers in /run/opengl-driver

So I should rather use a shell.nix to add the dependencies?

This solved it for me

https://nixos.wiki/wiki/Visual_Studio_Code#Use_VS_Code_extensions_without_additional_configuration