Build rust application issue`#![feature]` may not be used on the stable release channel

Hi there! I encounter a issue on building pyrefly nix package.

This is my default.nix

{
  lib,
  fetchFromGitHub,
  rustPlatform,
}:

rustPlatform.buildRustPackage (finalAttrs: {
  pname = "pyrefly";
  version = "0.16.0";

  src = fetchFromGitHub {
    owner = "facebook";
    repo = "pyrefly";
    tag = finalAttrs.version;
    hash = "sha256-41miHY4ycybH/dy2p2pH6FQPriVN2zPEOusVoRf8n9U=";
  };

  postPatch = ''
    ln -s ${./Cargo.lock} Cargo.lock
  '';

  cargoLock = {
    lockFile = ./Cargo.lock;
    outputHashes = {
      "ruff_python_ast-0.0.0" = "sha256-YQmkmn6fWKmKz+Lw9wwgPG2O9E+2/ZJcclRs97SOWK4=";
    };
  };

  sourceRoot = "${finalAttrs.src.name}/pyrefly";

  meta = {
    homepage = "https://github.com/facebook/pyrefly";
    description = "A fast type checker and IDE for Python ";
    mainProgram = "pyrefly";
    license = lib.licenses.mit;
    maintainers = [ ];
  };
})

Since pyrefly doesn’t include a Cargo.toml file. I manually download the 0.16.0 release source code and run cargo update inside it to get a Cargo.toml file and put it under the same directory with default.nix file.

I can build the pyrefly package successfully using normal cargo build command (i.e. cargo build --release) without Nix. And this is my rust toolchain:

❯ rustup show active-toolchain -v
stable-x86_64-unknown-linux-gnu (default)
rustc 1.86.0 (05f9846f8 2025-03-31)

However, I cannot build the package using Nix through this default.nix. Here is the issue:

error: builder for '/nix/store/w4zxws9wslb58ya5lr0qm059p5kldrna-pyrefly-0.16.0.drv' failed with exit code 101;
       last 25 log lines:
       >    Compiling toml_edit v0.22.26
       >    Compiling ruff_python_parser v0.0.0 (https://github.com/astral-sh/ruff/?rev=3acf4e716d5d1fb9bd1316dc268deb6824a300c8#3acf4e71)
       >    Compiling tokio v1.45.0
       >    Compiling prost v0.11.9
       >    Compiling serde_bser v0.4.0
       >    Compiling prost-types v0.11.9
       >    Compiling lsp-types v0.94.1
       >    Compiling lsp-server v0.7.8
       >    Compiling tracing-subscriber v0.3.19
       >    Compiling serde_with v1.14.0
       >    Compiling toml v0.8.22
       >    Compiling tokio-util v0.6.10
       >    Compiling indicatif v0.17.11
       >    Compiling lock_free_hashtable v0.1.1
       >    Compiling watchman_client v0.9.0
       >    Compiling static_interner v0.1.1
       > error[E0554]: `#![feature]` may not be used on the stable release channel
       >   --> /build/cargo-vendor-dir/static_interner-0.1.1/src/lib.rs:15:1
       >    |
       > 15 | #![feature(offset_of)]
       >    | ^^^^^^^^^^^^^^^^^^^^^^
       >
       > For more information about this error, try `rustc --explain E0554`.

The command to build is nix build -L .#pyrefly

I try to output the rust version using preBuild hook:

pyrefly> rustc 1.86.0 (05f9846f8 2025-03-31) (built from a source tarball)
pyrefly> cargo 1.86.0 (adf9b6ad1 2025-02-28)

I don’t know why this error occurs and how to solve it.

Thank you for your help! <3

Hi, im not sure if this will definently fix it as i can’t test right now, but try adding RUSTC_BOOTSTRAP = 1; into the buildRustPackage scope (e.g below version = "0.16.0";)

1 Like

Thank you! It works. <3


Though I’m still confused since offset_of feature has been stable since 1.77.0: offset_of in std::mem - Rust

nixpkgs rust docs mention that you can’t use nightly features by default, might be why

1 Like

Are you thinking of maybe opening up a PR on nixpkgs to get Pyrefly in as a package? It would be super useful!

It doesn’t support auto-completion, see LSP Integration Issues with Emacs · Issue #312 · facebook/pyrefly · GitHub. I don’t want to submit a semi-finished product.

1 Like