Errors using serde_derive with buildRustCrate

Wondering if anyone has any advice on this one. I’m building a Rust package which includes serde_derive and running into a list of errors that points to me needing some special rules with serde_derive.

So, I’ve made a repository that demonstrates the very initial problem. If you run nix build .#serde_test --print-build-logs in that repository, this is the problem you’ll run into:

rust_serde_test>   = help: message: file missing from serde_derive manifest directory during macro expansion: /build/serde_derive-1.0.181/serde_derive-x86_64-unknown-linux-gnu

I have tried a few things by overriding the build steps of the serde_derive crate:

  • I manually copied serde_derive-x86_64-unknown-linux-gnu into the serde_derive-1.0.181 target
  • I manually copied the libraries from the serde_derive component into the serde_derive-1.0.181-lib target

However, neither of these actually addressed the issue that the serde_test repository seems to want serde_derive-x86_64-unknown-linux-gnu in the build directory. Unfortunately, I don’t know how to reference serde_derive in the serde_test override, if I’m defining those overrides for the buildRustCrateForPackages parameter for the crate2nix derivation.

So, do you have any ideas?

      packages."x86_64-linux" =
          pkgs = import nixpkgs { system = "x86_64-linux"; };
          serde_test = (import ./Cargo.nix {
            inherit pkgs;
            buildRustCrateForPkgs = pkgs.defaultCrateOverrides // {
              serde_test = attrs: {
                preBuildPhase = ''
            release = true;

using serde_derive without precompiled binary · Issue #2538 · serde-rs/serde · GitHub - you can pin serde 1.0.171 as a workaround.