Pin rust version

I can use rust mozilla overlay to install the nightly rustc, but the version of rustc keeps changing with tha overlay. Is there something I can use to pin the rustc version to say, 1.43? I suppose that can be achieved by modifying that overlay for this functionality. I wanted to ask if there an existing solution that does that.

You can always just do the following with the mozilla overlay:

somewhere.nix:

  …
  mozilla-overlay = builtins.fetchTarball {
    url = https://github.com/mozilla/…;
    sha256 = "…";
  };`
  …
  nixpkgs = import <nixpkgs> {
    overlays = [
      (import mozilla-overlay)
      (import ./overlay.nix)
    ]
  };
  …

overlay.nix:

self: super: {
  rustNightlyChannel = super.rustChannelOf {
    date = "2019-12-19";
    channel = "nightly";
  };

  inherit (self.rustNightlyChannel) rust;
}

To get the rust version of the nightly channel from the 19th December
2019.

Note that @andir’s approach also works with stable versions. For example, to get 1.40.0:

(rustChannelOf { channel = "1.40.0"; }).rust

You can also use nixpkgs-mozilla as a package set, rather than an overlay. This is useful when you want to use it in e.g. a derivation:

{ callPackage, fetchFromGitHub }:

let
  mozillaOverlay = fetchFromGitHub {
    owner = "mozilla";
    repo = "nixpkgs-mozilla";
    rev = "9f35c4b09fd44a77227e79ff0c1b4b6a69dff533";
    sha256 = "18h0nvh55b5an4gmlgfbvwbyqj91bklf1zymis6lbdh75571qaz0";
  };
  mozilla = callPackage "${mozillaOverlay.out}/package-set.nix" {};
  rustNightly = (mozilla.rustChannelOf { date = "2019-07-30"; channel = "nightly"; }).rust;
  rustPlatform = makeRustPlatform { cargo = rustNightly; rustc = rustNightly; };
in rustPlatform.buildRustPackage rec {
  # ...
}
1 Like