Libssl.so.3 not found when compiling rust

I set up a rust dev environment via a flake and so far it worked fine. Now I’m trying to compile a rust program that uses the diesel postgres feature. Once the feature is included in the build, I get this error:

note: /nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: warning: libssl.so.3, needed by /nix/store/79azl2c2q2c8agjq5w111638npgdvy81-postgresql-14.6-lib/lib/libpq.so, not found (try using -rpath or -rpath-link)
          /nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: warning: libcrypto.so.3, needed by /nix/store/79azl2c2q2c8agjq5w111638npgdvy81-postgresql-14.6-lib/lib/libpq.so, not found (try using -rpath or -rpath-link)
          /nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: warning: libgssapi_krb5.so.2, needed by /nix/store/79azl2c2q2c8agjq5w111638npgdvy81-postgresql-14.6-lib/lib/libpq.so, not found (try using -rpath or -rpath-link)
          /nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/79azl2c2q2c8agjq5w111638npgdvy81-postgresql-14.6-lib/lib/libpq.so: undefined reference to `ENGINE_init@OPENSSL_3.0.0'

The PKG_CONFIG_PATH is set, this is what my flake looks like:

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        overlays = [ (import rust-overlay) ];
        pkgs = import nixpkgs { inherit system overlays; };
        # rustVersion = pkgs.rust-bin.stable."1.63.0".default;
        rustVersion = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
      in
      {
        devShell =
          pkgs.mkShell {
            buildInputs = [
              (rustVersion.override {
                extensions = [ "rust-src" ];
                targets = [ "wasm32-unknown-unknown" ];
              })
              pkgs.rustfmt
              #pkgs.rustc
              #pkgs.rustup
              pkgs.rust-analyzer
              pkgs.diesel-cli
              pkgs.httpie
              pkgs.postgresql
              pkgs.openssl
              pkgs.pkg-config
            ];
            shellHook = ''
              export PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig";
              export CARGO=/run/current-system/sw/bin/cargo
              export CARGO_HOME=/home/knut/.cargo
              export PATH="/run/current-system/sw/bin:/home/knut/.cargo/bin:/home/knut/.nix-profile/bin:$PATH"
              export RUST_SRC_PATH="${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"
            '';
          };
      }
    );
}

And when running pkg-config --libs-only-L openssl in the dev environment, I get the path

-L/nix/store/gw4hdapx2kipvjlwm8r4vg356abbi9xd-openssl-3.0.7/lib

Is there any good advice on how to solve this?

It’s likely a recent regression in nipkgs/master. Should be fixed by build-support/cc-wrapper: revert "pass in non-existent --sysroot= to … by trofi · Pull Request #213185 · NixOS/nixpkgs · GitHub. Try nixpkgs/staging-next to make sure it’s already fine there.

1 Like

Thanks a lot, that fixed it