add an example with buildRustPackage

authored by Eli Flanagan and committed by Raphael Megzari b829fe48 8650a7e6

+42
+42
doc/languages-frameworks/rust.section.md
··· 912 912 913 913 As of writing, this prints out `rustc 1.56.0 (09c42c458 2021-10-18)`. 914 914 915 + ### How to use an overlay toolchain in a derivation {#how-to-use-an-overlay-toolchain-in-a-derivation} 916 + 917 + You can also use an overlay's Rust toolchain with `buildRustPackage`. 918 + The below snippet demonstrates invoking `buildRustPackage` with an oxalica overlay selected Rust toolchain: 919 + ```nix 920 + with import <nixpkgs> 921 + { 922 + overlays = [ 923 + (import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) 924 + ]; 925 + }; 926 + 927 + rustPlatform.buildRustPackage rec { 928 + pname = "ripgrep"; 929 + version = "12.1.1"; 930 + nativeBuildInputs = [ 931 + rust-bin.stable.latest.minimal 932 + ]; 933 + 934 + src = fetchFromGitHub { 935 + owner = "BurntSushi"; 936 + repo = pname; 937 + rev = version; 938 + sha256 = "1hqps7l5qrjh9f914r5i6kmcz6f1yb951nv4lby0cjnp5l253kps"; 939 + }; 940 + 941 + cargoSha256 = "03wf9r2csi6jpa7v5sw5lpxkrk4wfzwmzx7k3991q3bdjzcwnnwp"; 942 + 943 + meta = with lib; { 944 + description = "A fast line-oriented regex search tool, similar to ag and ack"; 945 + homepage = "https://github.com/BurntSushi/ripgrep"; 946 + license = licenses.unlicense; 947 + maintainers = [ maintainers.tailhook ]; 948 + }; 949 + } 950 + ``` 951 + 952 + Follow the below steps to try that snippet. 953 + 1. create a new directory 954 + 1. save the above snippet as `default.nix` in that directory 955 + 1. cd into that directory and run `nix-build` 956 + 915 957 ### Rust overlay installation {#rust-overlay-installation} 916 958 917 959 You can use this overlay by either changing your local nixpkgs configuration,