Home

Awesome

rust-overlay

CI Sync channels

Pure and reproducible packaging of binary distributed rust toolchains. A compatible but better replacement for rust overlay of nixpkgs-mozilla, with also non-overlay and Nix Flake interfaces (despite the project name).

For migration from nixpkgs-mozilla, see this section.

Features:

Documentations:

Installation

Classic Nix overlay

You can put the code below into your ~/.config/nixpkgs/overlays.nix.

[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]

Then the provided attribute paths are available in nix command.

$ nix-env -iA nixpkgs.rust-bin.stable.latest.default # `nixpkgs` (or `nixos`) is your nixpkgs channel name.

Alternatively, you can install it into nix channels.

$ nix-channel --add https://github.com/oxalica/rust-overlay/archive/master.tar.gz rust-overlay
$ nix-channel --update

And then feel free to use it anywhere like import <nixpkgs> { overlays = [ (import <rust-overlay>) ]; } in your nix shell environment.

Nix Flakes

Warning: Only the output overlay/overlays are currently stable. Use other outputs at your own risk!

For a quick play, just use nix shell to bring the latest stable rust toolchain into scope. (All commands below requires preview version of Nix with flake support.)

$ nix shell github:oxalica/rust-overlay
$ rustc --version # This is only an example. You may get a newer version here.
rustc 1.49.0 (e1884a8e3 2020-12-29)
$ cargo --version
cargo 1.49.0 (d00d64df9 2020-12-05)

Use in NixOS Configuration

Here's an example of using it in nixos configuration.

{
  description = "My configuration";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, rust-overlay, ... }: {
    nixosConfigurations = {
      hostname = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix # Your system configuration.
          ({ pkgs, ... }: {
            nixpkgs.overlays = [ rust-overlay.overlays.default ];
            environment.systemPackages = [ pkgs.rust-bin.stable.latest.default ];
          })
        ];
      };
    };
  };
}

Use in devShell for nix develop

Running nix develop will create a shell with the default beta Rust toolchain installed:

{
  description = "A devShell example";

  inputs = {
    nixpkgs.url      = "github:NixOS/nixpkgs/nixos-unstable";
    rust-overlay.url = "github:oxalica/rust-overlay";
    flake-utils.url  = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        overlays = [ (import rust-overlay) ];
        pkgs = import nixpkgs {
          inherit system overlays;
        };
      in
      {
        devShells.default = with pkgs; mkShell {
          buildInputs = [
            openssl
            pkg-config
            eza
            fd
            rust-bin.beta.latest.default
          ];

          shellHook = ''
            alias ls=eza
            alias find=fd
          '';
        };
      }
    );
}

Migration from nixpkgs-mozilla

  1. Change the channel URL to https://github.com/oxalica/rust-overlay/archive/master.tar.gz, or flake URL to github:oxalica/rust-overlay for Nix Flakes.
  2. Good to go! latest.*, rustChannel*.* and friends are made compatible with nixpkgs-mozilla. You don't necessary need to change anything.
  3. You can also optionally change to the rust-bin interface, which provides more functionality like "latest nightly with specific components available" or "from rust-toolchain file". It also has nix-aware cross-compilation support.

Cheat sheet: common usage of rust-bin

License

MIT licensed.