2022-12-27 01:27:13 +03:00
|
|
|
## I need to patch `Cargo.lock` but when I do the build fails
|
|
|
|
|
|
|
|
Dependency crates are vendored by reading `Cargo.lock` _at evaluation time_ and
|
|
|
|
not at build time. Thus using `patches = [ ./patch-which-updates-lockfile.patch ];`
|
|
|
|
may result in a situation where any new crates introduced by the patch cannot be
|
|
|
|
found by cargo.
|
|
|
|
|
|
|
|
It is possible to work around this limitation by patching `Cargo.lock` in a
|
|
|
|
stand-alone derivation and passing that result to `vendorCargoDeps` before
|
|
|
|
building the rest of the workspace.
|
|
|
|
|
|
|
|
```nix
|
|
|
|
let
|
|
|
|
patchedCargoLock = src = pkgs.stdenv.mkDerivation {
|
|
|
|
src = ./path/to/Cargo.lock;
|
|
|
|
patches = [
|
|
|
|
./update-cargo-lock.patch
|
|
|
|
];
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out
|
|
|
|
cp Cargo.lock $out
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
craneLib.buildPackage {
|
|
|
|
cargoVendorDir = craneLib.vendorCargoDeps {
|
|
|
|
src = patchedCargoLock;
|
|
|
|
};
|
|
|
|
|
2023-03-20 06:57:15 +03:00
|
|
|
src = craneLib.cleanCargoSource (craneLib.path ./.);
|
2022-12-27 01:27:13 +03:00
|
|
|
|
|
|
|
patches = [
|
|
|
|
./update-cargo-lock.patch
|
|
|
|
./some-other.patch
|
|
|
|
];
|
|
|
|
}
|
|
|
|
```
|