Cannot install cargo dependency via git when workspace in subdirectory

I am trying to build a Rust package via buildRustPackage. It is a package within a workspace, and I’m pointing to the workspace Cargo.toml in the appropriate way.

edit: see comment below for a repo w/a minimal reproduction

All of this works as it should:

  # Use the Cargo lockfile to determine the package hash and inputs.
  cargoLock = {
    lockFile = ../../Cargo.lock;
  };

However, I have just added a git dependency to the Cargo.toml. I followed the recommended approach, adding the commit hash of the package into the cargoLock invocation:

  cargoLock = {
    lockFile = ../../Cargo.lock;
    outputHashes = {
      "apache-avro-0.16.0" = "sha256-r6ogb0RHbvea+07bO4+9WXQdQfJCFktG7V4UNqenIZE=";
    };
  };

The issue from there is that the package I’m trying to install is itself a workspace package, and its Cargo.toml is not at the root of the git repository. Specifically, this is the repository, this is the workspace, and this is the package.

There seems to be a baked in assumption somewhere that there will be a Cargo.toml at the root of the repo. When trying to build the above Rust package, I get the following error:

Found crate apache-avro at /nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/Cargo.toml
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/Cargo.toml' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/Cargo.toml'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/README.md' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/README.md'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/quickstop-null.avro' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/quickstop-null.avro'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/serde.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/serde.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/serde_json.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/serde_json.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/single.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/single.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/benchmark.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/benchmark.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/generate_interop_data.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/generate_interop_data.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/test_interop_data.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/test_interop_data.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/test_interop_single_object_encoding.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/test_interop_single_object_encoding.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/to_value.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/to_value.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/codec.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/codec.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/de.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/de.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/decimal.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/decimal.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/decode.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/decode.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/duration.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/duration.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/encode.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/encode.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/error.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/error.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/lib.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/lib.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/rabin.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/rabin.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/reader.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/reader.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/schema.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/schema.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/schema_compatibility.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/schema_compatibility.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/ser.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/ser.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/types.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/types.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/util.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/util.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/writer.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/writer.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/append_to_existing.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/append_to_existing.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/avro-3786.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/avro-3786.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/avro-3787.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/avro-3787.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/io.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/io.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/schema.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/schema.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/shared.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/shared.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/to_from_avro_datum_schemata.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/to_from_avro_datum_schemata.rs'
Traceback (most recent call last):
  File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 108, in <module>
    main()
  File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 71, in main
    top_cargo_toml = load_file(sys.argv[2])
  File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 15, in load_file
    with open(path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/Cargo.toml'
error: builder for '/nix/store/snp4aknx5l11bhlbhh0pkjylnq1sb1b3-apache-avro-0.16.0.drv' failed with exit code 1;
       last 10 log lines:
       > '/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/shared.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/shared.rs'
       > '/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/to_from_avro_datum_schemata.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/to_from_avro_datum_schemata.rs'
       > Traceback (most recent call last):
       >   File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 108, in <module>
       >     main()
       >   File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 71, in main
       >     top_cargo_toml = load_file(sys.argv[2])
       >   File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 15, in load_file
       >     with open(path, "rb") as f:
       > FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/Cargo.toml'
       For full logs, run 'nix log /nix/store/snp4aknx5l11bhlbhh0pkjylnq1sb1b3-apache-avro-0.16.0.drv'.
error: 1 dependencies of derivation '/nix/store/kwv2kkbj25nmhvpsnrdmhwhlmky1li7s-cargo-vendor-dir.drv' failed to build

The error seems to be coming from this file, but it’s not obvious to me why it would be looking for a Cargo.toml in the workspace root, especially not after having successfully replaced a variety of the nested files.

Any help would be greatly appreciated! Thank you!

Edit: most of the log content is replicated above in the console output, but here is the full error log just in case it’s helpful:

Looking at /nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/Cargo.toml
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/wasm-demo/Cargo.toml
workspace: /nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/Cargo.toml
Found crate apache-avro at /nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/Cargo.toml
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/Cargo.toml' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/Cargo.toml'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/README.md' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/README.md'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/quickstop-null.avro' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/quickstop-null.avro'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/serde.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/serde.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/serde_json.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/serde_json.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/benches/single.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/benches/single.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/benchmark.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/benchmark.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/generate_interop_data.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/generate_interop_data.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/test_interop_data.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/test_interop_data.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/test_interop_single_object_encoding.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/test_interop_single_object_encoding.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/examples/to_value.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/examples/to_value.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/codec.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/codec.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/de.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/de.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/decimal.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/decimal.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/decode.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/decode.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/duration.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/duration.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/encode.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/encode.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/error.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/error.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/lib.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/lib.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/rabin.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/rabin.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/reader.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/reader.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/schema.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/schema.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/schema_compatibility.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/schema_compatibility.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/ser.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/ser.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/types.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/types.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/util.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/util.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/src/writer.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/src/writer.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/append_to_existing.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/append_to_existing.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/avro-3786.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/avro-3786.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/avro-3787.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/avro-3787.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/io.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/io.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/schema.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/schema.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/shared.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/shared.rs'
'/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/lang/rust/avro/tests/to_from_avro_datum_schemata.rs' -> '/nix/store/4qc2wiq47v4nkliihfyxwabrz7jm4cd2-apache-avro-0.16.0/tests/to_from_avro_datum_schemata.rs'
Traceback (most recent call last):
  File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 108, in <module>
    main()
  File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 71, in main
    top_cargo_toml = load_file(sys.argv[2])
  File "/nix/store/r2dsj9lsd421zgyijmrffc77bg43417f-replace-workspace-values", line 15, in load_file
    with open(path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/lgyk2rx34q9jhjjxqa1rrwxvm8vlnkq7-avro-a88cc9e/Cargo.toml'

I created a simple reproduction of the issue here: ~mplanchard/nix-cargo-subdirectory-repro - Reproduction of nix issue installing rust packages from a workspace in a nested subdirectory of a git repo - sourcehut git

You should be able to clone, run nix build ., and see the error.

Ultimately, it’s the combination of this flake:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
      in
      {
        defaultPackage = pkgs.rustPlatform.buildRustPackage {
          pname = "rust-repo";
          src = ./.;
          version = "0.0.1";
          cargoLock = {
            lockFile  = ./Cargo.lock;
            outputHashes = {
              "apache-avro-0.16.0" = "sha256-V8VmkCIAZxPBYdP/c4EvkbbOfo/BqgGhYca+8A7ngVI=";
            };
          };
        };
        devShell = with pkgs; mkShell {
          buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ];
          RUST_SRC_PATH = rustPlatform.rustLibSrc;
        };
      });
}

and this Cargo.toml:

[package]
name = "nix-cargo-subdirectory-repro"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
apache-avro = { git = "https://github.com/apache/avro", branch = "master" }