Rust: Difference between revisions
Add example for how to overrideAttrs rust packages |
Add strictDeps to all mkShell |
||
| Line 12: | Line 12: | ||
Here's an example <code>shell.nix</code>: | Here's an example <code>shell.nix</code>: | ||
< | <syntaxhighlight lang="nix"> | ||
let | let | ||
# Pinned nixpkgs, deterministic. Last updated: 2/12/21. | # Pinned nixpkgs, deterministic. Last updated: 2/12/21. | ||
| Line 27: | Line 27: | ||
}: | }: | ||
mkShell { | mkShell { | ||
strictDeps = true; | |||
nativeBuildInputs = [ | nativeBuildInputs = [ | ||
cargo | cargo | ||
| Line 33: | Line 34: | ||
} | } | ||
) { } | ) { } | ||
</ | </syntaxhighlight> | ||
== Installating with bindgen support == | == Installating with bindgen support == | ||
| Line 40: | Line 41: | ||
Here's an example <code>shell.nix</code>: | Here's an example <code>shell.nix</code>: | ||
< | <syntaxhighlight lang="nix"> | ||
{ | { | ||
pkgs ? import <nixpkgs> { }, | pkgs ? import <nixpkgs> { }, | ||
| Line 53: | Line 54: | ||
}: | }: | ||
mkShell { | mkShell { | ||
strictDeps = true; | |||
nativeBuildInputs = [ | nativeBuildInputs = [ | ||
cargo | cargo | ||
| Line 67: | Line 69: | ||
} | } | ||
) { } | ) { } | ||
</ | </syntaxhighlight> | ||
This also works, when compiling rust crates: | This also works, when compiling rust crates: | ||
| Line 109: | Line 111: | ||
}: | }: | ||
mkShell { | mkShell { | ||
strictDeps = true; | |||
nativeBuildInputs = [ | nativeBuildInputs = [ | ||
rustup | rustup | ||
| Line 263: | Line 266: | ||
== Shell.nix example == | == Shell.nix example == | ||
< | <syntaxhighlight lang="nix"> | ||
{ | { | ||
pkgs ? import <nixpkgs> { }, | pkgs ? import <nixpkgs> { }, | ||
| Line 279: | Line 282: | ||
}: | }: | ||
mkShell { | mkShell { | ||
strictDeps = true; | |||
nativeBuildInputs = [ | nativeBuildInputs = [ | ||
rustc | rustc | ||
| Line 294: | Line 298: | ||
} | } | ||
) { } | ) { } | ||
</ | </syntaxhighlight> | ||
This will have the stable Rust compiler + the official formatter and linter inside the ephemeral shell. It'll also set the RUST_SRC_PATH environment variable to point to the right location, which tools, such as rust-analyzer, require to be set. | This will have the stable Rust compiler + the official formatter and linter inside the ephemeral shell. It'll also set the RUST_SRC_PATH environment variable to point to the right location, which tools, such as rust-analyzer, require to be set. | ||
| Line 332: | Line 336: | ||
}: | }: | ||
mkShell { | mkShell { | ||
strictDeps = true; | |||
# host/target agnostic programs | # host/target agnostic programs | ||
depsBuildBuild = [ | depsBuildBuild = [ | ||
| Line 377: | Line 382: | ||
}: | }: | ||
mkShell { | mkShell { | ||
strictDeps = true; | |||
nativeBuildInputs = [ | nativeBuildInputs = [ | ||
my-rust-toolchain | my-rust-toolchain | ||