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 library needs staged Cargo.lock #46

Closed
MalteT opened this issue Nov 7, 2021 · 4 comments · Fixed by #47
Closed

Building library needs staged Cargo.lock #46

MalteT opened this issue Nov 7, 2021 · 4 comments · Fixed by #47

Comments

@MalteT
Copy link
Contributor

MalteT commented Nov 7, 2021

When using this project in a Rust library with flakes, the following error occurs:

error: A Cargo.lock file must be present, please make sure it's at least staged in git.
(use '--show-trace' to show detailed location information)

This is probably not a problem with nix-cargo-integration, but with the way purity is handled. Is there any workaround other than just staging Cargo.lock (and unstaging for every commit)?

Thanks for the awesome work!

@yusdacra
Copy link
Owner

yusdacra commented Nov 7, 2021

Yes, this is intended. I would recommend to just commit the Cargo.lock file, since it ensures reproducibility in general. In case of libraries, this might be a problem with CI, but that can be resolved via removing the Cargo.lock file before build.

I'm not aware of a workaround that would allow the Cargo.lock to be ignored by git but still be picked up by Nix (using flakes), as flakes will only pick up files that are at least staged in git.

If you don't want to / can't commit the Cargo.lock, one possible option is to make a command that will stage Cargo.lock, run nix build, and then unstage it, and add it to devshell. That would at least make it less of a headache.

@bew
Copy link
Contributor

bew commented Nov 7, 2021

I'm not aware of a workaround that would allow the Cargo.lock to be ignored by git but still be picked up by Nix (using flakes), as flakes will only pick up files that are at least staged in git.

I know one: git add -N Cargo.lock or long form: git add --intend-to-add Cargo.lock

It will make the file known by git but without staging or committing it

@MalteT
Copy link
Contributor Author

MalteT commented Nov 7, 2021

I know one: git add -N Cargo.lock or long form: git add --intend-to-add Cargo.lock

What is this witchery? Works perfectly!

Yes, this is intended. I would recommend to just commit the Cargo.lock file, since it ensures reproducibility in general. In case of libraries, this might be a problem with CI, but that can be resolved via removing the Cargo.lock file before build.
You're probably right, but the official recommendation is to not do that for libraries, iirc.

@bew's fix works quite well. I guess this can be closed now. Or should there be some documentation about this?

@yusdacra
Copy link
Owner

yusdacra commented Nov 7, 2021

I'm not aware of a workaround that would allow the Cargo.lock to be ignored by git but still be picked up by Nix (using flakes), as flakes will only pick up files that are at least staged in git.

I know one: git add -N Cargo.lock or long form: git add --intend-to-add Cargo.lock

It will make the file known by git but without staging or committing it

Oh wow, TIL. From the man page:

-N, --intent-to-add
           Record only the fact that the path will be added later. An entry for the path is placed in the index with
           no content. This is useful for, among other things, showing the unstaged content of such files with git
           diff and committing them with git commit -a.

Thanks for that!

bew's fix works quite well. I guess this can be closed now. Or should there be some documentation about this?

Yes, this should be documented. I would appreciate a PR 🙂 We can probably create a "Tips and tricks" or similar section in MANUAL.md, and put it there.

MalteT added a commit to MalteT/nix-cargo-integration that referenced this issue Nov 7, 2021
Contains the tip regarding handling `Cargo.lock` when building a library (see yusdacra#46)
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.

3 participants