naersk
naersk copied to clipboard
Error when using a `git` dependency that includes a workspace, when the flake is also in a workspace
I don't know if my attempt at a short title makes sense, but I'm encountering a bug with the following setup:
- My repository has a workspace with multiple packages
- The workspace depends on sqlx via git (it points to my personal fork of sqlx)
- I build one of those packages in my flake via naersk
Naersk errors with the following log:
https://cache.nixos.org/jdj7x0j6nqfwwbxdi7817jp6c8q8pb06.narinfo
unpacking sources
unpacking source archive /nix/store/7j4556lxs9rjb0zblkkb0f6j40mmhv20-dummy-src
source root is dummy-src
patching sources
configuring
[naersk] cargo_version (read): 1.71.1 (7f1d04c00 2023-07-29)
[naersk] cargo_message_format (set): json-diagnostic-rendered-ansi
[naersk] cargo_release: --profile release-server
[naersk] cargo_options:
[naersk] cargo_build_options: $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format --package bibs-server
[naersk] cargo_test_options: $cargo_release -j "$NIX_BUILD_CORES" --package bibs-server
[naersk] RUST_TEST_THREADS: 8
[naersk] cargo_bins_jq_filter: .
[naersk] cargo_build_output_json (created): /build/tmp.P8anP0GEYc
[naersk] RUSTFLAGS:
[naersk] CARGO_BUILD_RUSTFLAGS:
[naersk] CARGO_BUILD_RUSTFLAGS (updated): --remap-path-prefix /nix/store/qfyhwwg326nr5vxg1p5av2ic7c4qikld-crates-io-dependencies=/sources --remap-path-prefix /nix/store/kdhdx724l1xxwn2740s2xac2qkywaxyj-git-dependencies=/sources
building
cargo build $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format --package bibs-server
error: failed to get `sqlx` as a dependency of package `bibs-server v0.1.0 (/build/dummy-src/bibs-server)`
Caused by:
failed to load source for dependency `sqlx`
Caused by:
Unable to update https://github.com/jelle-bigbridge/sqlx.git?branch=add-local-infile#9b9b8c41
Caused by:
failed to update replaced source https://github.com/jelle-bigbridge/sqlx.git?branch=add-local-infile#9b9b8c41
Caused by:
failed to parse manifest at `/nix/store/kdhdx724l1xxwn2740s2xac2qkywaxyj-git-dependencies/sqlx-macros-0.7.1-add-local-infile/Cargo.toml`
Caused by:
error inheriting `version` from workspace root manifest's `workspace.package.version`
Caused by:
failed to find a workspace root
[naersk] cargo returned with exit code 101, exiting
I hope that my PR with sqlx is merged soon and they will release a crates.io crate with my fix, but until then my code will have to depend on my own fork. I don't know if this is easily fixed or not, at least a workaround would be greatly appreciated.
I am facing this same issue while trying to build typst-preview. Interestingly, one of the dependencies, typst, is a flake, but the package I am building is not a flake. Here are the relevant logs,
error: failed to load source for dependency `typst`
Caused by:
Unable to update https://github.com/Myriad-Dreamin/typst.git?rev=c7e91e216310d5c8dca3eee8a23a64b3ede99e15#c7e91e21
Caused by:
failed to update replaced source https://github.com/Myriad-Dreamin/typst.git?rev=c7e91e216310d5c8dca3eee8a23a64b3ede99e15#c7e91e21
Caused by:
failed to parse manifest at `/nix/store/1m7xmazviaayrbhvbpgc00jh2lfqz8y5-git-dependencies/typst-0.8.0-c7e91e216310d5c8dca3eee8a23a64b3ede99e15/Cargo.toml`
Caused by:
error inheriting `version` from workspace root manifest's `workspace.package.version`
Caused by:
failed to find a workspace root
Ah, I see - the issue is that Naersk copies all dependencies into a flat structure, i.e. it takes:
deps/something
deps/typst
deps/typst/typst-foo
deps/typst/typst-bar
... and flattens it into:
deps/something
deps/typst-foo
deps/typst-bar
... which causes things like version.workspace to fail, unable to locate the workspace's Cargo.toml.
It seems that Crane handles this correctly, so for the time being I'd suggest checking it out; I don't have much time to prepare a fix now, but if someone wants to, feel free!
I also hit the version.workspace bug - hopefully a nix wizard can submit a fix for the rest of us 😅
tauri-plugin-single-instance also seems to trigger this
just hit it