nix-community / fenix

Rust toolchains and rust-analyzer nightly for Nix [maintainer=@figsoda]
Mozilla Public License 2.0
668 stars 42 forks source link

Doesn't work in Rust 1.59.0+ without remote dependencies #70

Closed CobaltCause closed 2 years ago

CobaltCause commented 2 years ago

Using 89ac7f1e75cd2edd38cb5a876e6587b79f01c17a or later results in the following error while using a freshly generated project from this template:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/rrxjykvlq9bym14wmp3ymia2ivq8wx2m-qzpy5x97aq5wkmq02vqjq6sqgavr06v9-source
source root is qzpy5x97aq5wkmq02vqjq6sqgavr06v9-source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
no configure script, doing nothing
@nix { "action": "setPhase", "phase": "buildPhase" }
building
There is no dependency to vendor in this project.
Traceback (most recent call last):
  File "/nix/store/z0xnb7i6f9lypw2x4yf0br6fypg762pk-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 42, in <module>
    main()
  File "/nix/store/z0xnb7i6f9lypw2x4yf0br6fypg762pk-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 17, in main
    assert list(data.keys()) == ["source"]
AssertionError

Workarounds:

  1. Add at least one remote dependency (i.e. having only dependencies with path = "..." or no dependencies at all won't work)
  2. Use the previous fenix commit in flake.nix (and then run nix flake update to update the lockfile) like so:
inputs = {
  fenix = {
    url = "github:nix-community/fenix?rev=a372f826fbc2148fe6fac619c2ff93fd89e9896b";
    #                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    inputs.nixpkgs.follows = "nixpkgs";
  };
};

The There is no dependency to vendor in this project. message comes from cargo itself and is new in Rust/Cargo 1.59.0. I think this line is what's actually causing Nix builds to fail. I know nothing of fenix internals but maybe it needs to be modified to conditionally call cargo vendor or to mkdir -p the vendor directory after calling cargo vendor with newer versions of Cargo? I think this is probably an upstream bug in buildRustPackage in nixpkgs.

CobaltCause commented 2 years ago

Okay, it turns out that specifying cargoSha256 causes this issue and specifying cargoLock.lockFile instead works fine. Though, I'm still not sure why cargoSha256 was causing this issue. Since I now know a workaround plus the root cause is in nixpkgs and not fenix, I'm going to close this issue.