/doc/languages-frameworks/rust.md

https://github.com/cbpark/nixpkgs · Markdown · 90 lines · 66 code · 24 blank · 0 comment · 0 complexity · ca83f5d6910956688a7c65dd66daa603 MD5 · raw file

  1. ---
  2. title: Rust
  3. author: Matthias Beyer
  4. date: 2017-03-05
  5. ---
  6. # User's Guide to the Rust Infrastructure
  7. To install the rust compiler and cargo put
  8. ```
  9. rust
  10. ```
  11. into the `environment.systemPackages` or bring them into
  12. scope with `nix-shell -p rust`.
  13. For daily builds (beta and nightly) use either rustup from
  14. nixpkgs or use the [Rust nightlies
  15. overlay](#using-the-rust-nightlies-overlay).
  16. ## Packaging Rust applications
  17. Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`:
  18. ```
  19. with rustPlatform;
  20. buildRustPackage rec {
  21. name = "ripgrep-${version}";
  22. version = "0.4.0";
  23. src = fetchFromGitHub {
  24. owner = "BurntSushi";
  25. repo = "ripgrep";
  26. rev = "${version}";
  27. sha256 = "0y5d1n6hkw85jb3rblcxqas2fp82h3nghssa4xqrhqnz25l799pj";
  28. };
  29. cargoSha256 = "0q68qyl2h6i0qsz82z840myxlnjay8p1w5z7hfyr8fqp7wgwa9cx";
  30. meta = with stdenv.lib; {
  31. description = "A utility that combines the usability of The Silver Searcher with the raw speed of grep";
  32. homepage = https://github.com/BurntSushi/ripgrep;
  33. license = with licenses; [ unlicense ];
  34. maintainers = [ maintainers.tailhook ];
  35. platforms = platforms.all;
  36. };
  37. }
  38. ```
  39. `buildRustPackage` requires a `cargoSha256` attribute which is computed over
  40. all crate sources of this package. Currently it is obtained by inserting a
  41. fake checksum into the expression and building the package once. The correct
  42. checksum can be then take from the failed build.
  43. To install crates with nix there is also an experimental project called
  44. [nixcrates](https://github.com/fractalide/nixcrates).
  45. ## Using the Rust nightlies overlay
  46. Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into scope.
  47. This overlay can _also_ be used to install recent unstable or stable versions
  48. of Rust, if desired.
  49. To use this overlay, clone
  50. [nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla),
  51. and create a symbolic link to the file
  52. [rust-overlay.nix](https://github.com/mozilla/nixpkgs-mozilla/blob/master/rust-overlay.nix)
  53. in the `~/.config/nixpkgs/overlays` directory.
  54. $ git clone https://github.com/mozilla/nixpkgs-mozilla.git
  55. $ mkdir -p ~/.config/nixpkgs/overlays
  56. $ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix
  57. The latest version can be installed with the following command:
  58. $ nix-env -Ai nixos.latest.rustChannels.stable.rust
  59. Or using the attribute with nix-shell:
  60. $ nix-shell -p nixos.latest.rustChannels.stable.rust
  61. To install the beta or nightly channel, "stable" should be substituted by
  62. "nightly" or "beta", or
  63. use the function provided by this overlay to pull a version based on a
  64. build date.
  65. The overlay automatically updates itself as it uses the same source as
  66. [rustup](https://www.rustup.rs/).