dten
December 2, 2024, 6:33pm
1
Hey thanks for looking
I’m trying to make a derivation for the boon cli from GitHub - santhosh-tekuri/boon: JSONSchema (draft 2020-12, draft 2019-09, draft-7, draft-6, draft-4) Validation in Rust
I have this from following the docs and looking at other existing derivations for related things.
{ stdenv, lib, rustPlatform, fetchFromGitHub }:
rustPlatform.buildRustPackage rec {
pname = "boon-cli";
version = "0.6.0";
src = fetchFromGitHub {
owner = "santhosh-tekuri";
repo = "boon";
rev = "v${version}";
sha256 = "sha256-evXxahueOlFxkWnJbB7kxhvD/WMTVEFEiKvdEl5MWbU=";
};
cargoRoot = "cli";
cargoHash = "sha256-oxasA7UoyQGCLnh+cm1otlokh9zifOfPYYTq5dfUwQ4=";
meta = with stdenv.lib; {
description = "JSONSchema (draft 2020-12, draft 2019-09, draft-7, draft-6, draft-4) Validation in Rust";
homepage = "https://github.com/santhosh-tekuri/boon";
license = lib.licenses.mit;
};
}
However when I run it i get the following error. This is after having done the steps to fix it. I tried doing the steps for all the hashes just in case one was being weird but nothing is working.
error: builder for '/nix/store/7m5i7d0h31vpal30ckqg1wz709cd1jnj-boon-cli-0.6.0.drv' failed with exit code 1;
last 25 log lines:
> 584c1019,1025
> < version = "0.52.5"
> ---
> > version = "0.48.5"
> > source = "registry+https://github.com/rust-lang/crates.io-index"
> > checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
> >
> > [[package]]
> > name = "windows_x86_64_msvc"
> > version = "0.52.0"
> 586c1027
> < checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
> ---
> > checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
>
> ERROR: cargoHash or cargoSha256 is out of date
>
> Cargo.lock is not the same in /build/boon-cli-0.6.0-vendor.tar.gz
>
> To fix the issue:
> 1. Set cargoHash/cargoSha256 to an empty string: `cargoHash = "";`
> 2. Build the derivation and wait for it to fail with a hash mismatch
> 3. Copy the "got: sha256-..." value back into the cargoHash field
> You should have: cargoHash = "sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=";
>
For full logs, run 'nix log /nix/store/7m5i7d0h31vpal30ckqg1wz709cd1jnj-boon-cli-0.6.0.drv'.
I have a suspicion that the slightly odd set up with a cli Cargo.toml/lock referencing the library via relative path might be related, but i couldn’t see for certain that it is.
Any help very much appreciated thank you
dten
December 2, 2024, 9:03pm
2
I think I might have found why it’s not working! I’ve resorted to forking the repository and moving things around so the cli is in the root for now. Couldn’t get any tips from the issue to work without doing that
NixOS:master
← TomaSajt:cargo-root
opened 07:51PM - 22 Oct 24 UTC
This PR adds `cargoRoot` support to `fetchCargoTarball` and `fetchCargoVendor` a… nd modifies `buildRustPackage` to also pass `cargoRoot` to its fetcher.
---
`cargoRoot` was added as a way to have `cargoSetupHook` be run inside a specific directory, when `sourceRoot` wasn't enough. (e.g. when the rust code was in a subdirectory, but the main build is not started from inside that).
This support, however, was not extended to the FOD based fetchers: `fetchCargoTarball` and `fetchCargoVendor`
ATM we have to do
```nix
cargoDeps = rustPlatform.fetchCargoTarball {
sourceRoot = "${src.name}/${cargoRoot}"
}
```
for `fetchCargoTarball` to find the `Cargo.lock` file.
Unfortunately, adding `cargoRoot` to the args passed to `buildRustPackage` doesn't forward any information to the fetcher.
This was mostly fine, since `buildRustPackage` almost never needed `cargoRoot`, and the workaround mentioned above works fine for non-`buildRustPackage` cases.
---
However, after the introduction of the `cargo-tauri.hook` -- which was supposed to work fine alongside `buildRustPackage`, overriding `cargoBuildHook` behaviour -- `cargoRoot` started becoming required to build those packages.
This was not really an issue, since most tauri apps used `cargoLock.lockFile` and a vendored `Cargo.lock` file, because tauri apps very often use git dependencies. This meant that `cargoRoot` was never required to be set.
Now that `fetchCargoVendor` is a thing, which actually works with git dependencies, this PR starts becoming more relevant than before.
---
PR where originally I encountered this issue: https://github.com/NixOS/nixpkgs/pull/348901 (rare occurence of not needing to use `cargoLock.lockfile`)
---
You might say that when using `cargo-tauri.hook` we should just manually use `cargoSetupHook` and leave `buildRustPackage` alone, which is fair.
But the fetcher should at least have a proper way to support `cargoRoot`. This way you could just to `inherit pname version src cargoRoot;` inside `fetchCargoTarball`, instead of doing the weird `sourceRoot` method
---
In this PR I have 3 commits:
1. the actual functionality change.
2. `cargo-tauri.hook` based package working fine with `fetchCargoTarball` backend
3. `cargo-tauri.hook` based package working fine with `fetchCargoVendor` backend
<!--
^ Please summarise the changes you have done and explain why they are necessary here ^
For package updates please link to a changelog or describe changes, this helps your fellow maintainers discover breaking updates.
For new packages please briefly describe the package or provide a link to its homepage.
-->
## Things done
- Built on platform(s)
- [x] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] `sandbox = relaxed`
- [ ] `sandbox = true`
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#linking-nixos-module-tests-to-a-package) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [24.11 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) (or backporting [23.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2311.section.md) and [24.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2405.section.md) Release notes)
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [ ] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
<!--
To help with the large amounts of pull requests, we would appreciate your
reviews of other pull requests, especially simple package updates. Just leave a
comment describing what you have tested in the relevant package/service.
Reviewing helps to reduce the average time-to-merge for everyone.
Thanks a lot if you do!
List of open PRs: https://github.com/NixOS/nixpkgs/pulls
Reviewing guidelines: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#reviewing-contributions
-->
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
What steps? And what was fixed?
ghpzin
December 2, 2024, 9:07pm
4
You can set sourceRoot
instead, this seems to build (thought I would not be able to explain why):
{
stdenv,
lib,
rustPlatform,
fetchFromGitHub,
}:
rustPlatform.buildRustPackage rec {
pname = "boon-cli";
version = "0.6.0";
src = fetchFromGitHub {
owner = "santhosh-tekuri";
repo = "boon";
rev = "v${version}";
sha256 = "sha256-evXxahueOlFxkWnJbB7kxhvD/WMTVEFEiKvdEl5MWbU=";
};
sourceRoot = "${src.name}/cli";
cargoHash = "sha256-Gk48H8BmuLFD99FNNZizxSiOVqSKdhYY9ihgtD7lnng=";
meta = {
description = "JSONSchema (draft 2020-12, draft 2019-09, draft-7, draft-6, draft-4) Validation in Rust";
homepage = "https://github.com/santhosh-tekuri/boon";
license = lib.licenses.mit;
};
}
dten
December 2, 2024, 9:34pm
5
What steps? And what was fixed?
I mean the steps that the error message suggests on how to fix it.
You can set sourceRoot
instead
Thank you @ghpzin that’s really helpful! I can’t believe I didn’t try that. I thought that would cause it to not be able to find the parent source.