Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing field unused for key patch #308

Closed
jmgilman opened this issue Sep 5, 2023 · 1 comment · Fixed by #309
Closed

missing field unused for key patch #308

jmgilman opened this issue Sep 5, 2023 · 1 comment · Fixed by #309

Comments

@jmgilman
Copy link

jmgilman commented Sep 5, 2023

 > error: failed to parse lock file at: /build/dummy-src/Cargo.lock
 >
 > Caused by:
 >   missing field `unused` for key `patch`
 > [naersk] cargo returned with exit code 101, exiting

I am getting the above error when building a lockfile with entries like:

[[patch.unused]]
name = "package"
version = "0.1.0"
source = "git+https://github.com/org/repo.git?branch=mybranch#efe089af522e424d1099407b6585efe042ad085f"

I can run this same lockfile with cargo outside of Nix and it compiles fine. I'm having trouble understanding what specifically is making it break when trying to build it with naersk.

Patryk27 added a commit that referenced this issue Sep 6, 2023
Cargo stashes unused patches into a special section of the Cargo.lock
file:

```
[[patch.unused]]
name = "uuid"
version = "1.4.1"
source = "git+https://github.com/uuid-rs/uuid#50f70278de02c106650b8d6deb325dd59b5f2a24"
```

... a section that we, currently, don't read.

Ignoring that section causes the build to fail because even if the patch
is unused, when the source is unavailable, Cargo tries to fetch it
(which, understandably, is not possible inside the sandbox).

This commit extends our logic so that we download both the "used" and
"unused" dependencies.

Closes #308.
@Patryk27
Copy link
Contributor

Patryk27 commented Sep 6, 2023

Curiously, there's one-and-a-half worth of bugs here!

tl;dr I've just prepared a fix - after it's merged, you'll have to update your Nixpkgs to a newer version (at least 23, i.e. current master or nixpkgs-unstable), and then bump Naersk.


First, when Naersk builds a derivation, it converts Cargo.lock into a Nix attrset and then reserializes that attrset back into a TOML document later - this serialization-code has had a bug that caused the eventual Cargo.lock to look like:

[patch]
[[unused]]
name = "package"
version = "0.1.0"
source = "..."

... which Cargo (rightfully) doesn't understand anymore.

This bug has been fixed recently, but the fix only works when Naersk is launched on Nixpkgs 23+ (because older versions of Nixpkgs had a buggy serializer as well) - so, in principle, if you switched to a newer Nixpkgs (e.g. nix flake lock --update-input naersk --update-input nixpkgs), it should work.

But, as it turns out, there's second thing at play here - because Naersk doesn't provide sources for ignored dependencies, trying to actually compile such project will fail, saying:

failed to resolve address for github.com: nodename nor servname provided, or not known; class=Net (12)

... as Cargo will try to download the "missing" dependency on its own, while being locked in Nix sandbox, which fails.

This is a bug on Naersk's side, for which I've just prepared a fix.

Patryk27 added a commit that referenced this issue Sep 6, 2023
Cargo stashes unused patches into a special section of the Cargo.lock
file:

```
[[patch.unused]]
name = "uuid"
version = "1.4.1"
source = "git+https://github.com/uuid-rs/uuid#50f70278de02c106650b8d6deb325dd59b5f2a24"
```

... a section that we, currently, don't read.

Ignoring that section causes the build to fail because even if the patch
is unused, when the source is unavailable, Cargo tries to fetch it
(which, understandably, is not possible inside the sandbox).

This commit extends our logic so that we download both the "used" and
"unused" dependencies.

Closes #308.
Patryk27 added a commit that referenced this issue Sep 7, 2023
Cargo stashes unused patches into a special section of the Cargo.lock
file:

```
[[patch.unused]]
name = "uuid"
version = "1.4.1"
source = "git+https://github.com/uuid-rs/uuid#50f70278de02c106650b8d6deb325dd59b5f2a24"
```

... a section that we, currently, don't read.

Ignoring that section causes the build to fail because even if the patch
is unused, when the source is unavailable, Cargo tries to fetch it
(which, understandably, is not possible inside the sandbox).

This commit extends our logic so that we download both the "used" and
"unused" dependencies.

Closes #308.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants