Jump to content

Rust: Difference between revisions

27 bytes removed ,  27 February
m
Add some fixes, notably with devenv.sh
imported>Mbwk
m (fix: use rust-analyzer from the overlay or else you'll face version mismatch errors)
imported>TenTypekMatus
m (Add some fixes, notably with devenv.sh)
Line 5: Line 5:
# or with unofficial overlays on nixpkgs.  
# or with unofficial overlays on nixpkgs.  


Installing via nixpkgs is the nix-iest way to use Rust, but there are valid reasons to use any approach.
Installing via nixpkgs is the best way to use Rust, but there are valid reasons to use any approach.


== Installing via nixpkgs ==
== Installing via nixpkgs ==
The <code>cargo</code> and <code>rustc</code> derivations provide the Rust toolchain in nixpkgs. An advantage of using nixpkgs is that it's dead simple and you get pinned versions, deterministic builds in nix-shell, etc. However, nixpkgs only maintains a single version of the Rust stable toolchain, so if you require a nightly toolchain or require switching between multiple toolchains then this approach may not be for you.  
The <code>cargo</code> and <code>rustc</code> derivations provide the Rust toolchain in nixpkgs. An advantage of using nixpkgs is that it's dead simple and you get pinned versions, deterministic builds in nix-shell, etc. However, nixpkgs only maintains a single version of the Rust stable toolchain, so if you require a nightly toolchain or switch between multiple toolchains then this approach may not be for you.  


Here's an example <code>shell.nix</code>:
Here's an example <code>shell.nix</code>:
Line 27: Line 27:
The rustup tool is maintained by the Rust community and offers an interface to install and switch between Rust toolchains. In this scenario, rustup handles the "package management" of Rust toolchains and places them in <code>$PATH</code>. Nixpkgs offers rustup via the <code>rustup</code> derivation. More info on using rustup can be found on their official website: https://rustup.rs/.
The rustup tool is maintained by the Rust community and offers an interface to install and switch between Rust toolchains. In this scenario, rustup handles the "package management" of Rust toolchains and places them in <code>$PATH</code>. Nixpkgs offers rustup via the <code>rustup</code> derivation. More info on using rustup can be found on their official website: https://rustup.rs/.


If you want to have the most "normal" Rust experience I recommend using rustup with the following example shell.nix:
If you want the most "normal" Rust experience I recommend using rustup with the following example shell.nix:
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {} }:
Line 48: Line 48:
       # add libraries here (e.g. pkgs.libvmi)
       # add libraries here (e.g. pkgs.libvmi)
     ]);
     ]);
     # Add glibc, clang, glib and other headers to bindgen search path
     # Add glibc, clang, glib, and other headers to bindgen search path
     BINDGEN_EXTRA_CLANG_ARGS =  
     BINDGEN_EXTRA_CLANG_ARGS =  
     # Includes with normal include path
     # Includes normal include path
     (builtins.map (a: ''-I"${a}/include"'') [
     (builtins.map (a: ''-I"${a}/include"'') [
       # add dev libraries here (e.g. pkgs.libvmi.dev)
       # add dev libraries here (e.g. pkgs.libvmi.dev)
Line 89: Line 89:
== devenv.sh support ==
== devenv.sh support ==


# https://github.com/cachix/devenv/blob/main/examples/rust/devenv.nix and [code]devenv shell[/code]
# https://github.com/cachix/devenv/blob/main/examples/rust/devenv.nix and <code>devenv shell</code>


== Rust Nightlies ==
== Rust Nightlies ==