HDF5 `include` and `lib` for Rust's hdf5 crate

The Nix hdf5 package has two outputs:

  • out contains lib etc.
  • dev contains include etc.

as can be seen here

$ ls /nix/store/*-hdf5-1.10.6/   
bin/  lib/  share/
$ ls /nix/store/*-hdf5-1.10.6-dev/   
bin/  include/  nix-support/

Rust’s hdf5 crate, expects to find lib and include under the same directory (which it calls HDF5_DIR). This leaves me with the choice of failing to find either inculde or lib:

  • HDF5_DIR = "${pkgs.hdf5}";include not found
  • HDF5_DIR = "${pkgs.hdf5.dev}";lib not found

How can I make both lib and include appear in the same HDF5_DIR directory?

-------------------------------------------------

For completeness, here are the shell.nix and Cargo.toml I am using for testing this

shell.nix


{ nixpkgs-commit-id ? "7badbf18c45b7490d893452beb8950d966327831" # nixos-20.09 on 2020-10-07
}:
let
  nixpkgs-url = "https://github.com/nixos/nixpkgs/archive/${nixpkgs-commit-id}.tar.gz";
  pkgs = import (fetchTarball nixpkgs-url) {
      overlays = map (uri: import (fetchTarball uri)) [
        https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
      ];
    };

  buildInputs = [
    (pkgs.latest.rustChannels.stable.rust.override {} )
    pkgs.pkgconfig
    pkgs.hdf5
  ];
in
pkgs.stdenv.mkDerivation {
  name = "rust-hdf5";
  buildInputs = buildInputs;
  LD_LIBRARY_PATH = "${pkgs.stdenv.lib.makeLibraryPath buildInputs}";
  HDF5_DIR = "${pkgs.hdf5}"; # or pkgs.hdf5.dev
}

Cargo.toml

[package]
name = "hdf5-nix-rust"
version = "0.1.0"
edition = "2018"

[dependencies]
hdf5 = "0.7"

You may consider joining outputs with symlinkJoin. For example:

symlinkJoin { name = "hdf5"; paths = [ hdf5 hdf5.dev ]; }
1 Like