Last active
August 17, 2025 12:58
-
-
Save polyfloyd/9e8acf73ec86a6c4e211a980c11b1712 to your computer and use it in GitHub Desktop.
Nix flake for rust-esp toolchain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| inputs = { | |
| nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |
| }; | |
| outputs = | |
| { self, nixpkgs }: | |
| let | |
| rust-src = | |
| { stdenv, fetchzip }: | |
| stdenv.mkDerivation { | |
| name = "rust-src"; | |
| src = fetchzip rec { | |
| version = "1.88.0.0"; | |
| name = "rust-src-archive"; | |
| url = "https://github.com/esp-rs/rust-build/releases/download/v${version}/rust-src-${version}.tar.xz"; | |
| hash = "sha256-zWuLI2+q0rO9ANFZOEwLHbvaO+ZANI/MJpj/JBrhxiQ="; | |
| }; | |
| installPhase = '' | |
| bash ./install.sh --prefix=$out | |
| ''; | |
| }; | |
| rust-esp.x86_64-linux = | |
| { | |
| stdenv, | |
| fetchzip, | |
| rust-src, | |
| }: | |
| stdenv.mkDerivation { | |
| name = "rust-esp"; | |
| src = fetchzip rec { | |
| version = "1.88.0.0"; | |
| name = "rust-esp"; | |
| url = "https://github.com/esp-rs/rust-build/releases/download/v${version}/rust-${version}-x86_64-unknown-linux-gnu.tar.xz"; | |
| hash = "sha256-rVASQiHRC+sJvi9rdVsO8IO0fAZKKGFqRzmSoR5faj0="; | |
| }; | |
| installPhase = '' | |
| bash ./install.sh --prefix=$out | |
| ln -s ${rust-src}/lib/rustlib/src $out/lib/rustlib/src | |
| ''; | |
| }; | |
| xtensa-esp-elf.x86_64-linux = | |
| { fetchzip }: | |
| fetchzip rec { | |
| version = "15.1.0_20250607"; | |
| name = "xtensa-esp-elf"; | |
| url = "https://github.com/espressif/crosstool-NG/releases/download/esp-${version}/xtensa-esp-elf-${version}-x86_64-linux-gnu.tar.gz"; | |
| hash = "sha256-OLm7JQeeFdvTbga1s6D0aMFVGWjNhG023t/aHX+xxz0="; | |
| }; | |
| xtensa-esp32-elf-clang.x86_64-linux = | |
| { fetchzip }: | |
| fetchzip rec { | |
| version = "18.1.2_20240912"; | |
| name = "xtensa-esp-elf"; | |
| url = "https://github.com/espressif/llvm-project/releases/download/esp-${version}/clang-esp-${version}-x86_64-linux-gnu.tar.xz"; | |
| hash = "sha256-ejG1QYVjZ7Ije6eOZqLf7QOF7eALC5BQj9orOqL4Vr8="; | |
| }; | |
| in | |
| rec { | |
| packages = nixpkgs.lib.genAttrs [ "x86_64-linux" ] ( | |
| system: | |
| let | |
| pkgs = nixpkgs.legacyPackages.${system}; | |
| in | |
| { | |
| rust-esp = pkgs.callPackage rust-esp.${system} { | |
| rust-src = pkgs.callPackage rust-src { }; | |
| }; | |
| xtensa-esp-elf = pkgs.callPackage xtensa-esp-elf.${system} { }; | |
| xtensa-esp32-elf-clang = pkgs.callPackage xtensa-esp32-elf-clang.${system} { }; | |
| } | |
| ); | |
| devShells = nixpkgs.lib.genAttrs [ "x86_64-linux" ] ( | |
| system: | |
| let | |
| pkgs = nixpkgs.legacyPackages.${system}; | |
| in | |
| { | |
| default = pkgs.mkShell { | |
| packages = [ | |
| pkgs.espflash | |
| packages.${system}.rust-esp | |
| packages.${system}.xtensa-esp-elf | |
| packages.${system}.xtensa-esp32-elf-clang | |
| ]; | |
| LIBCLANG_PATH = "${packages.${system}.xtensa-esp32-elf-clang}/lib"; | |
| }; | |
| } | |
| ); | |
| }; | |
| } |
Author
It depends on the project at the moment. For projects I have cargo, rust-analyzer and etc. installed via a shell.nix that is loaded via direnv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have been looking for this solution everywhere. Thank you so much for posting it here!
If you have some time to help a nix noob I would greatly appreciate the help. How are you also getting the normal rust tools (cargo, rust-analyzer, clippy, etc.). I'm trying to make my own dev environment for my project have all the necessary tools.