Cmake cannot find openssl in nix-shell

In CMakeLists.txt, a simple find_package(OpenSSL REQUIRED) does not work inside a pure nix shell.

$ nix-shell --pure -p cmake openssl cacert pkg-config python3 gtest git
nix-shell$ cmake --build build/relwithdebinfo --config RelWithDebInfo
CMake Error at /nix/store/9cbpyw2256lkll43i97438fhb26h0xvc-cmake-3.31.6/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
  version "3.4.1")

Can someone help me figure out a fix?

EDIT: As soon as I posted, I figured out that the issue could an OpenSSL related config and found it: OPENSSL_USE_STATIC_LIBS TRUE. Why does this work outside nix-shell on nixos though?

EDIT2: pkg_check_modules(OpenSSL REQUIRED openssl) also makes it work inside nix-shell. Why?

The fix seems to be to use pkgsStatic.openssl instead.