This is my flakeless configuration for macOS using nix
{
  pkgs,
  lib,
  config,
  ...
}:
let
  fenix = import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") { };
  enableWasm = false;
  nightly = false;
  toolchain = if nightly then fenix.default else fenix.stable;
  wasmTarget = if nightly then "default" else "stable";
  fenixPackage =
    with fenix;
    combine ([
      (toolchain.withComponents ["cargo" "rustc" "rust-src" "rust-analyzer"])
    ]
    ++ lib.optional enableWasm [ targets.wasm32-unknown-unknown.${wasmTarget}.rust-std ]);
in
{
  home.sessionVariables.CARGO_HOME = "${config.xdg.dataHome}/cargo";
  home.sessionVariables.RUSTUP_HOME = "${config.xdg.dataHome}/rustup";

  home.packages = [ fenixPackage ] ++ lib.optional enableWasm [ pkgs.trunk ];
  programs.nixvim.plugins.lsp.servers.rust-analyzer = {
    enable = true;
    package = null;
    installCargo = false;
    installRustc = false;
    extraOptions = {
      settings = {
        rust-analyzer = {
          checkOnSave = {
            command = "clippy";
          };
        };
      };
    };
  };
}