docs: add more examples for overriding rust-toolchain

This commit is contained in:
Yusuf Bera Ertan 2022-07-06 20:30:17 +03:00
parent 89bfa7c971
commit 757501574f
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA

View File

@ -21,6 +21,8 @@ Builds a package using `buildRustPackage` from `nixpkgs`.
### crane (ifd)
Builds a package using [`crane`](https://github.com/ipetkov/crane).
This builder builds two seperate derivations, one for dependencies and the other for your crate.
The dependencies derivation will be named `<crate>-deps` where `<crate>` is the name of the crate you are building.
#### Override gotchas
@ -84,7 +86,7 @@ You can also of course override the toolchain for only certain crates:
}
```
#### crane notes
#### `crane` notes
The crane builder does not require a `rustc` package in the toolchain specified, only a `cargo` package is needed.
If cross-compiling, keep in mind that it also takes `cargo` packages like so:
@ -116,3 +118,51 @@ in
# ...
}
```
#### Examples
- Usage with [fenix](https://github.com/nix-community/fenix):
```nix
let
# ...
# we use the full toolchain derivation here as using
# only the cargo / rustc derivation *does not* work.
toolchain = fenix.packages.${system}.minimal.toolchain;
# ...
in
{
# ...
packageOverrides = {
# for crane builder
"^.*".set-toolchain.overrideRustToolchain = old: {cargo = toolchain};
# for build-rust-package builder
"^.*".set-toolchain.overrideRustToolchain = old: {
cargo = toolchain;
rustc = toolchain;
};
};
# ...
}
```
- Usage with [oxalica's rust-overlay](https://github.com/oxalica/rust-overlay):
```nix
let
# ...
toolchain = rust-overlay.packages.${system}.rust;
# ...
in
{
# ...
packageOverrides = {
# for crane builder
"^.*".set-toolchain.overrideRustToolchain = old: {cargo = toolchain};
# for build-rust-package builder
"^.*".set-toolchain.overrideRustToolchain = old: {
cargo = toolchain;
rustc = toolchain;
};
};
# ...
}
```