Setting Up JupyterLab with a Rust Server Using Nix on Mac OS

First make sure that Nix package manager is installed on your system.

Here is a script that will install it for multiple users:

$ sh <(curl -L https://nixos.org/nix/install) --daemon

This code is from the official documentation.

Then create a new folder for your project and create a shell.nix file with the following contents:

{ pkgs ? import <nixpkgs> {}, system ? builtins.currentSystem }:

let
  isDarwin = system == "x86_64-darwin" || system == "aarch64-darwin";
  lib = pkgs.lib;
  darwinFrameworks = if isDarwin then with pkgs.darwin.apple_sdk.frameworks; [
    CoreServices
  ] else [];
in

pkgs.mkShell {
  buildInputs = [
    pkgs.rustup
    pkgs.nodejs
    (pkgs.python3.withPackages (ps: with ps; [
      jupyterlab
      ipykernel
    ]))
  ] ++ lib.optional isDarwin pkgs.libiconv ++ darwinFrameworks;

  shellHook = ''
    source ${pkgs.rustup}/etc/profile.d/rustup.sh

    rustup update
    rustup component add rust-src

    if command -v cargo &>/dev/null; then
      cargo install evcxr_jupyter
      evcxr_jupyter --install
    else
      echo "Cargo is not available in the PATH. Please ensure Rust is installed and configured correctly."
    fi
  '';
}

Activate the shell:

nix-shell

Run Jupyter Lab:

jupyter lab

You should now have an option to create notebooks with the Rust kernel.