Rust package error: requires newer rustc

I packaged a rust program with rustPlatform.buildRustPackage. When I try to build it, I get an error error: package 'time-macros v0.2.7' cannot be built because it requires rustc 1.62.0 or newer, while the currently active rustc version is 1.60.0. However, I’m on up-to-date unstable which is on rustc 1.67.1 (here).

I tried to add rustc to nativeBuildInputs, but the error persists. How can I get the package to build with a newer rustc?

Can you post the nix expression you are working with?

{ lib, fetchFromGitHub, rustPlatform, rustc, lz4, pkg-config, libxkbcommon }:

rustPlatform.buildRustPackage {
  pname = "swww";
  version = "0.7.2";

  src = fetchFromGitHub {
    owner = "Horus645";
    repo = "swww";
    rev = "v0.7.2";
    hash = "sha256-1SmCeIlcjOX3yCvpfqQ82uq4h2xlGhX9OCwKb6jGK78=";
  };

  cargoSha256 = "sha256-08YM9yTCRJPHdOc1+7F3guYiP3y1WSi3/hzlDRVpitc=";

  buildInputs = [ lz4 libxkbcommon ];
  nativeBuildInputs = [ pkg-config rustc ];
  cargoPatches = [ ./Cargo.patch ];

  doCheck = false;

  meta = with lib; {
    description = "Efficient animated wallpaper daemon for wayland, controlled at runtime";
    longDescription = ''
      `swww` is an efficient animated wallpaper daemon for wayland, controlled at runtime'';
    homepage = "https://github.com/Horus645/swww";
    license = with licenses; [ gpl3 ];
    maintainers = with maintainers; [ todor ];
  };
}

rustc shouldn’t need to be in nativeBuildInputs with buildRustPackage. not sure why you would get this error, what branch/revision of nixpkgs are you using?

I was able to build the package successfully with this expression based on code generated with nix-init.

{ lib
, rustPlatform
, fetchFromGitHub
, pkg-config
, libxkbcommon
, wayland
}:

rustPlatform.buildRustPackage rec {
  pname = "swww";
  version = "0.7.2";

  src = fetchFromGitHub {
    owner = "Horus645";
    repo = "swww";
    rev = "v${version}";
    hash = "sha256-1SmCeIlcjOX3yCvpfqQ82uq4h2xlGhX9OCwKb6jGK78=";
  };

  cargoHash = "sha256-08YM9yTCRJPHdOc1+7F3guYiP3y1WSi3/hzlDRVpitc=";

  nativeBuildInputs = [
    pkg-config
  ];

  buildInputs = [
    libxkbcommon
    wayland
  ];

  meta = with lib; {
    description = "Efficient animated wallpaper daemon for wayland, controlled at runtime";
    homepage = "https://github.com/Horus645/swww";
    changelog = "https://github.com/Horus645/swww/blob/${src.rev}/CHANGELOG.md";
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ todor ];
    platforms = platforms.linux;
  };
}

My config uses flakes and my flake is on latest unstable revision from today. I tried to build it and it worked - so I guess the derivation’s fine. Thanks.

Previously I was trying to build the package with nix-build -E 'let pkgs = import <nixpkgs> {}; in pkgs.callPackage (import ./default.nix) {}' because I’m not sure what the equivalent new interface would be. So I guess my problem was caused by using the nix-build interface, and it uses an older revision of nixpkgs for some reason. Why might that be?

It is because <nixpkgs> finds the nixpkgs in your $NIX_PATH, which probably contains a version of rustc that is outdated for the package.

I am encountering a similar issue as a Nix neophyte trying to build a Rust application that requires rustc 1.72.0 or newer, using buildRustPackage. I see that a more recent version of the Rust compiler is available in the unstable channel; is there some way to make use of that version from my derivation?

For the record, this is the error I am seeing running nix-build:

error: package `derive_more v1.0.0-beta.6` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.69.0

and I am using the nixos-23.05 channel, hence the Rust compiler version of 1.69.0. Ultimately I would like to try and contribute to nixpkgs, if that makes a difference in how I go about tackling this issue.

@crimeminister I’m a recent nix convert too, in part because I needed better control of a dev environment with rust and other wasm tools like cargo-component, etc. Nix has now replaced all my previous uses of asdf.

This cli command should drop you into a local shell with rust 1.73.0:

nix develop 'git+https://github.com/stevelr/nix?dir=shells/rust-latest'

The source is here.

I don’t think the rustc in the environment (what the dev shell will affect) has any effect on the nix build process. It creates a new, sandboxed environment for itself.

At least in my case, the issue was that I’m using flakes, but I also had some old channels lying around that I wasn’t updating. Hence the old version.

I don’t know whan 1.69.0 landed in 11.05, but you do need to have updated the channels and rebuilt after that to have it locally.

This is what I ended up doing to solve my issue, allowing me to run nix-build to compile the Rust application I am working on.

# Note that currently stable rust toolchain is 1.69.0. We require at
# least 1.73.0 to build this application. For details of how to use a
# more recent version of the Rust compiler via a community-maintained
# see:
#
# https://nixos.org/manual/nixpkgs/stable/#using-community-maintained-rust-toolchains
#
# Use the oxalica Rust overlay to make use of the latest stable version
# of the Rust compiler.

with import <nixpkgs>
{
  overlays = [
    (import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"))
  ];
};
let
  rustPlatform = makeRustPlatform {
    cargo = rust-bin.stable.latest.minimal;
    rustc = rust-bin.stable.latest.minimal;
  };
in
rustPlatform.buildRustPackage rec {

Not out of the woods yet, the tests for the application are failing which is blocking the build from completing successfully. Now to puzzle out how to disable them from being compiled/executed until they’re fixed upstream.

Turns out disabling tests was as easy as:

doCheck = false;

in my derivation. Now to figure out how to contribute to nixpkgs.