How to install OpenSSL to compile against?

Hi nix community, loving the idea behind nix/nixos.

I’m trying out nixos and nix (in docker) to host a rust program. It’s asking me to set OPENSSL_DIR or OPENSSL_LIB_DIR, I installed:

nix-env -iA nixos.openssl

  1. Is that the right package or is there a -dev package somewhere?
  2. Do I need to give it some flags (somehow) for nix to install the openssl lib and includes?
  3. Is there a recommended way to pick up the dir that nix is using for openssl?

Thanks in advance,


This lead me to the answers:

The lib, includes are in a dir with ‘-dev’ appended in the /nix/store rather than in the standard dir.
TODO: Find nice way to pick up that dir.

1 Like

openssl is a split package (with multiple outputs). Read more about it there especially “using a split package”
The dir your are looking for is actually the attribute in nix parlance.

Side comment: openssl still points to v1.0.2. If you are starting a fresh project you might want to use openssl_1_1_0 :

nix-env -iA nixos.openssl_1_1_0
1 Like

Adding to the answer from Linus, you probably don’t want to use nix-env for this. Typical cases

  • you want to do the full build of the program via a nix-build (you need to write a nix expression for that); or
  • you want a development environment via nix-shell -p openssl (writing shell.nix can be useful for complex cases or repeated usage).
1 Like

That’s really working well.