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,

Giles

1 Like

This lead me to the answers:
https://github.com/NixOS/nixpkgs/issues/15011

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.

https://nixos.wiki/wiki/FAQ/Libraries

3 Likes

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 openssl.dev 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).
3 Likes

That’s really working well.

or not. thread ‘main’ panicked at /home/gilescope/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openssl-sys-0.9.93/build/main.rs:79:9:
OpenSSL include directory does not exist: /home/gilescope/.nix-profile/bin/openssl/include

The answer is to get every project in the world to compile with rustls by default. That’s the only way right? Or could I perhaps get into a shell that has the includes hanging about? I just want cargo install cargo-raze to work. I get this with every tool that tries to use openssl. It’s so boring. (no pun intended)

This directory seems really suspicious. Even searching includes inside bin. And you surely don’t want to involve nix-profile anyway, as that brings more issues than advantages (I wrote about that in my previous post).

2 Likes

Good spot. I was overriding in my .zshrc the OPENSSL_DIR to try and point it to somewhere to make it work. Clearly that short term fix tripped me up!