I am building a package of a rust software from a git repo, but this repo does not contain the Cargo.lock file.
To make the pckg, I use buildRustPackage and according to the nix manual, if there is no Cargo.lock file, we have to use a patch :
rustPlatform.buildRustPackage rec {
# ...
cargoPatches = [
# a patch file to add/update Cargo.lock in the source code
./add-Cargo.lock.patch
];
}
The problem is that it is not specified what to put inside this file add-Cargo.lock.patch.
I tried with to put the whole Cargo.lock code locally generated by using diff -u /dev/null Cargo.lock > add-Cargo.lock.patch
But the build does not work because the Cargo.lock file does not exist.
So do I need to create firstly the file ? inside add-Cargo.lock.patch ?
I don’t really know, it’s the first time I use patches.
If you’re in the git repo, and you’ve generated the lockfile, you first might need to remove the Cargo.lock file from .gitignore, then you can do git add Cargo.lock and then run git diff --cached Cargo.lock to generate a diff from the staged files.
Or if you want to go the other route, you could just vendor the Cargo.lock file itself, next to your .nix file and do
However, the best solution might be to ask upstream to add the lockfile to the repo, since it’s recommended anyways. Once they committed the fix, you can use fetchpatch to fetch the diffs of the commit adding the lockfile. This is better, since putting a huge patch files and lockfiles into nixpkgs can increase the size of the repo quite a bit.
For those who interested in a solution, as @TomaSajt said, if you can’t have a Carg.lock in the depo, you have to build it locally and add it near your default.nix file.