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

Building crate that has a git submodule that is a crate that one depends on as a path dependency seems to fail? #287

Closed
molysgaard opened this issue May 6, 2023 · 4 comments

Comments

@molysgaard
Copy link

molysgaard commented May 6, 2023

Description

I have rust crate, that lives in a git repo.
It has a dependency, that is a git submodule. And I am using

my-dependency = { path = ./path/to/submodule }

In my Cargo.toml to depend on it.

nix build fails.

I have created a test repository with a minimal reproducible example: https://github.com/molysgaard/naersk-issuereport

Maybe I am doing something wrong, if so, I would be very happy for guidance in how to do it right. If not, I am interested in support for this use case.

Readme of minimal example repo below:

This repository shows an error I am getting when I am trying to use Naersk to compile a rust crate which has a git submodule inside it.

To reproduce:

# clone the repo
git clone https://github.com/molysgaard/naersk-issuereport.git

# go into the new repository
cd naersk-issuereport

# fetch the repos submodule
git submodule update --init --recursive

# try to build using naersk
nix build

Observe the following error:

user@hostname:~/naersk-issuereport$ nix build
error: builder for '/nix/store/llvlnxiia6x2zasq7i462wyk5m3dgq9c-parent-crate-deps-0.1.0.drv' failed with exit code 101;
       last 10 log lines:
       >
       > Caused by:
       >   Unable to update /build/dummy-src/itoa
       >
       > Caused by:
       >   failed to read `/build/dummy-src/itoa/Cargo.toml`
       >
       > Caused by:
       >   No such file or directory (os error 2)
       > [naersk] cargo returned with exit code 101, exiting
       For full logs, run 'nix log /nix/store/llvlnxiia6x2zasq7i462wyk5m3dgq9c-parent-crate-deps-0.1.0.drv'.
error: 1 dependencies of derivation '/nix/store/lrfy8vpac86qdcy9i2ma57mkh02457h2-parent-crate-0.1.0.drv' failed to build

On inspecting the dummy-src/ directory, there is no itoa directory, implying that the submodule has not been fetched for some reason.

@Patryk27
Copy link
Contributor

Patryk27 commented May 6, 2023

Could you try passing gitSubmodules = true; to buildPackage? 👀

@molysgaard
Copy link
Author

I think I am already doing it. Check the example repository?

@Patryk27
Copy link
Contributor

Patryk27 commented May 7, 2023

Ah, right - I didn't see that on the phone 😅

So, in this case you're actually hitting a limitation of Nix:
NixOS/nix#6633
... where doing src = ./.; causes Nix to present the source directory to Naersk without the submodules.

This can be worked around by doing:

defaultPackage = naersk-lib.buildPackage {
  src = self; # voilà
};

... committing all the changes (so that you have a clean Git tree, it's important) and then running:

nix build '.?submodules=1'

I think there's nothing Naersk could do on its side to overcome this issue, since we just read the src directory Nix prepares and there's no way to tell Nix to force-initialize-submodules from within Nix code.

Fortunately, there's a pull request to improve this:
NixOS/nix#7862

@molysgaard
Copy link
Author

I was able to get around this by removing the submodule and instead using cargo to fetch the dependency for me. Thanks for looking into this!

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

No branches or pull requests

2 participants