Rust: Difference between revisions

From NixOS Wiki
imported>Jtojnar
m do not use pkgconfig alias
imported>Michcioperz
Fix neovim completion (relevant dirs were moved out of src since 2017)
Line 1: Line 1:
[[Category:Languages]]
This article is about the [rust programming language](https://www.rust-lang.org).
 
This article is about the [https://www.rust-lang.org rust programming language].


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


Either use [https://nixos.org/nixpkgs/manual/#using-the-rust-nightlies-overlay rust overlay] or rustup to get install rust nightlies.
Either use [rust overlay](https://nixos.org/nixpkgs/manual/#using-the-rust-nightlies-overlay) or rustup to get install rust nightlies.


== Neovim Completion ==
== Neovim Completion ==
Line 22: Line 20:
         inherit (rustc.src) name;
         inherit (rustc.src) name;
         phases = ["unpackPhase" "installPhase"];
         phases = ["unpackPhase" "installPhase"];
         installPhase = "cp -r src $out";
         installPhase = ''cp -r library $out'';
       }}'
       }}'
     '';
     '';
Line 32: Line 30:
})
})
</syntaxHighlight>
</syntaxHighlight>
== Emacs integration ==
Making Emacs use certain version of libraries can be tricky, in particular for example OpenSSL might not be found ''even'' if it is in your Nix store. Two solutions exists :
* a "global" one
* a per-project one
Both solution relies on the usage of a library called [https://github.com/direnv/direnv/wiki/Nix direnv] and its package integration in Emacs [https://github.com/wbolster/emacs-direnv emacs-direnv].
=== Global solution ===
If you happen to have all of your Rust projects in one folder "<code>/path/to/your/rust</code>" then placing a file <code>/path/to/your/rust/.envrc</code> with this content :
<syntaxHighlight lang="shell">
use_nix
</syntaxHighlight>
and  another file <code>/path/to/your/rust/default.nix</code> :
<syntaxHighlight lang="Nix">
let
  moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
  nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
  ruststable = (nixpkgs.latest.rustChannels.stable.rust.override { extensions = [ "rust-src" "rls-preview" "rust-analysis" "rustfmt-preview" ];});
in
  with nixpkgs;
  stdenv.mkDerivation {
    name = "rust";
    buildInputs = [ openssl pkg-config nasm rustup ruststable cmake zlib ];
  }
</syntaxHighlight>
will, for example, grant you a free acces to OpenSSL ! Feel free to override this to your liking !
=== Per-project solution ===
For a more granular solution to this problem a more in-depth review of [https://github.com/direnv/direnv/wiki/Nix#persistent-shell-for-speeding-things-up the direnv wiki] will be poorly be needed !

Revision as of 10:59, 23 January 2021

This article is about the [rust programming language](https://www.rust-lang.org).

Rust Nightlies

Either use [rust overlay](https://nixos.org/nixpkgs/manual/#using-the-rust-nightlies-overlay) or rustup to get install rust nightlies.

Neovim Completion

Racer completion can be configured using the following snippet:

(neovim.override {
  configure = {
    customRC = ''
      if filereadable($HOME . "/.vimrc")
        source ~/.vimrc
      endif
      let $RUST_SRC_PATH = '${stdenv.mkDerivation {
        inherit (rustc) src;
        inherit (rustc.src) name;
        phases = ["unpackPhase" "installPhase"];
        installPhase = ''cp -r library $out'';
      }}'
    '';
    packages.nixbundle.start = with vimPlugins; [
      nvim-completion-manager
      nvim-cm-racer
    ];
  };
})