Skip to content

Known Restrictions

crate2nix makes heavy use of buildRustCrate in nixpkgs. So we potentially depend on features in a recent version of nixpkgs. Check flake.lock for the version of nixpkgs that crate2nix is tested against.

If you feel limited by these restrictions, please do not hesitate to file an issue! That gives me a feeling of what is worth working on.

  • There is only experimental support for running tests Before 0.7.x: No support for building and running tests, see nixpkgs, issue 59177.
  • A crate will only have access to its own source directory during build time and not e.g. to other directories in the same workspace. See #346. As a workaround, override the crate’s src with a wider directory and set workspace_member to the crate’s path inside it (see Crate Overrides), e.g. my-crate = attrs: { src = ./.; workspace_member = "crates/my-crate"; };. The crate is then rebuilt whenever anything in that wider directory changes.
  • It does translates target strings to nix expressions. The support should be reasonable but probably not complete - please let me know if you hit problems. Before 0.2.x: Filters all dependencies for the hard-coded “Linux x86_64” target platform. Again, it should be quite easy to support more platforms. To do so completely and at build time (vs build generation time) might be more involved.
  • CARGO_CRATE_NAME is the name of the library (with - replaced by _) for all targets of a package. cargo sets it per target: e.g. build_script_build for the build script and the binary’s name for a binary. buildRustCrate compiles all targets of a package in one derivation and has no way to set environment variables per rustc call, so it is only right for the library and for binaries named like the package (the default binary). Setting it per target belongs in buildRustCrate in nixpkgs. See #158.

Former restrictions, now supported:

  • Binaries with required-features were built even if the features were not enabled, see #129. Binaries whose required features are not enabled are now skipped, as with cargo.

  • Before 0.16.x: Features are resolved per package, not per role: a crate used both as a build dependency (or by a proc-macro) and as a normal dependency gets the union of the features of both uses, unlike cargo’s resolver 2. Features are now resolved as by cargo’s feature resolver “2” when the project uses it (edition 2021 or later, or resolver = "2"). See Feature resolver.

  • Before 0.8.x: Since cargo exposes local paths in package IDs, the generated build file also contain them as part of an “opaque” ID. They are not interpreted as paths but maybe you do not want to expose local paths in there… The full opaque package ID will only be used if you have the same package with the same version multiple times. That should be very rare.

  • Before 0.6.x: Renamed crates with an explicit package name don’t work yet.

  • Git sources are now also supported. Starting with 0.7 sub modules also work. Finding crates in arbitrary sub directories of git sources (which cargo supports!)is not supported, see #53.

  • Before 0.4.x: Only default crate features are supported. It should be easy to support a different feature set at build generation time since we can simply pass this set to cargo metadata. Feature selection during build time is out of scope for now.