Rust: Difference between revisions

Artturin (talk | contribs)
Add example for how to overrideAttrs rust packages
Artturin (talk | contribs)
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">
<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>
</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">
<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>
</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">
<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>
</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