From 58fd3db51ef0d7e99fe9e67ff4d0591e45a52694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=A4nner?= Date: Thu, 23 Jan 2025 11:06:49 +0100 Subject: [PATCH] add esp-idf tooling --- esp-idf.nix | 20 ++++++++++++++++ esp-rom-elfs.nix | 21 ++++++++++++++++ flake.lock | 54 +++++++++++++++++++++++++++++++++++++++++- flake.nix | 8 +++++++ openocd-esp32.nix | 38 +++++++++++++++++++++++++++++ xtensa-esp-elf-gdb.nix | 43 +++++++++++++++++++++++++++++++++ xtensa-esp-elf.nix | 37 +++++++++++++++++++++++++++++ 7 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 esp-idf.nix create mode 100644 esp-rom-elfs.nix create mode 100644 openocd-esp32.nix create mode 100644 xtensa-esp-elf-gdb.nix create mode 100644 xtensa-esp-elf.nix diff --git a/esp-idf.nix b/esp-idf.nix new file mode 100644 index 0000000..d1a27f5 --- /dev/null +++ b/esp-idf.nix @@ -0,0 +1,20 @@ +{ + pkgs ? import {}, + system ? builtins.currentSystem, +}: +pkgs.stdenv.mkDerivation rec { + pname = "esp-idf"; + version = "5.4"; + src = pkgs.fetchFromGitHub { + owner = "espressif"; + repo = "esp-idf"; + rev = "v${version}"; + fetchSubmodules = true; + hash = "sha256-9OQ/0DGwgfR3MkRWd6zSe1FD3Ywt4Ugw8J/BFu1Vfw0="; + }; + + buildInputs = with pkgs; [ + python3 + libusb1 + ]; +} diff --git a/esp-rom-elfs.nix b/esp-rom-elfs.nix new file mode 100644 index 0000000..9b5d37a --- /dev/null +++ b/esp-rom-elfs.nix @@ -0,0 +1,21 @@ +{pkgs}: +pkgs.stdenv.mkDerivation rec { + pname = "esp-rom-elfs"; + version = "20241011"; + src = + builtins.fetchurl + { + url = "https://github.com/espressif/${pname}/releases/download/${version}/${pname}-${version}.tar.gz"; + sha256 = "sha256:1ag9z459pgr7rmjxqfl8a6mayjiqffqmbvmzixicf8d4ch0h07wj"; + }; + + preferLocalBuild = true; + + dontUnpack = true; + + installPhase = '' + mkdir -p "$out" + cd "$out" + tar -xf $src + ''; +} diff --git a/flake.lock b/flake.lock index 2537edd..5a55bb1 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -34,10 +50,46 @@ "type": "github" } }, + "nixpkgs-python": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1733319315, + "narHash": "sha256-cFQBdRmtIZFVjr2P6NkaCOp7dddF93BC0CXBwFZFaN0=", + "owner": "cachix", + "repo": "nixpkgs-python", + "rev": "01263eeb28c09f143d59cd6b0b7c4cc8478efd48", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "nixpkgs-python", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1719253556, + "narHash": "sha256-A/76RFUVxZ/7Y8+OMVL1Lc8LRhBxZ8ZE2bpMnvZ1VpY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fc07dc3bdf2956ddd64f24612ea7fc894933eb2e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-python": "nixpkgs-python" } }, "systems": { diff --git a/flake.nix b/flake.nix index 955f268..2eda556 100644 --- a/flake.nix +++ b/flake.nix @@ -4,20 +4,28 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; + nixpkgs-python.url = "github:cachix/nixpkgs-python"; }; outputs = { nixpkgs, + nixpkgs-python, flake-utils, ... }: flake-utils.lib.eachDefaultSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; + pkgs-python = nixpkgs-python.packages.${system}; in { packages = rec { rust = import ./rust.nix {inherit pkgs system;}; clang = import ./clang.nix {inherit pkgs system;}; + esp-idf = import ./esp-idf.nix {inherit pkgs system;}; + openocd-esp32 = import ./openocd-esp32.nix {inherit pkgs system;}; + xtensa-esp-elf-gdb = import ./xtensa-esp-elf-gdb.nix {inherit pkgs pkgs-python system;}; + xtensa-esp-elf = import ./xtensa-esp-elf.nix {inherit pkgs system;}; + esp-rom-elfs = import ./esp-rom-elfs.nix {inherit pkgs;}; default = rust; }; } diff --git a/openocd-esp32.nix b/openocd-esp32.nix new file mode 100644 index 0000000..072321a --- /dev/null +++ b/openocd-esp32.nix @@ -0,0 +1,38 @@ +{ + pkgs, + system, +}: let + systems_table = { + "x86_64-linux" = { + system = "linux-amd64"; + hash = "1pw54ja4fmhy4rlaq8hirp5na8xvj5pah2azmnz494n9dl1hyaz8"; + }; + }; + system_download = systems_table.${system}; +in + pkgs.stdenv.mkDerivation rec { + pname = "openocd-esp32"; + version = "0.12.0-esp32-20241016"; + src = + builtins.fetchurl + { + url = "https://github.com/espressif/${pname}/releases/download/v${version}/${pname}-${system_download.system}-${version}.tar.gz"; + sha256 = system_download.hash; + }; + + preferLocalBuild = true; + + nativeBuildInputs = with pkgs; [ + autoPatchelfHook + ]; + + buildInputs = with pkgs; [ + systemd + libusb1 + ]; + + installPhase = '' + mkdir -p "$out" + cp -R ./{bin,share} "$out" + ''; + } diff --git a/xtensa-esp-elf-gdb.nix b/xtensa-esp-elf-gdb.nix new file mode 100644 index 0000000..eb7a0f2 --- /dev/null +++ b/xtensa-esp-elf-gdb.nix @@ -0,0 +1,43 @@ +{ + pkgs, + pkgs-python, + system, +}: let + systems_table = { + "x86_64-linux" = { + system = "x86_64-linux-gnu"; + hash = "sha256:0g9lk7snccn5464fs1mpyhylmvra0bvn6icqpbsxgixis94l6xqq"; + }; + }; + system_download = systems_table.${system}; +in + pkgs.stdenv.mkDerivation rec { + pname = "xtensa-esp-elf-gdb"; + version = "15.2_20241112"; + src = + builtins.fetchurl + { + url = "https://github.com/espressif/binutils-gdb/releases/download/esp-gdb-v${version}/${pname}-${version}-${system_download.system}.tar.gz"; + sha256 = system_download.hash; + }; + + preferLocalBuild = true; + + nativeBuildInputs = with pkgs; [ + autoPatchelfHook + ]; + + buildInputs = with pkgs; [ + pkgs-python."3.8" + pkgs-python."3.9" + pkgs-python."3.10" + pkgs-python."3.11" + pkgs-python."3.12" + pkgs-python."3.13" + ]; + + installPhase = '' + mkdir -p "$out" + cp -R ./{bin,lib} "$out" + ''; + } diff --git a/xtensa-esp-elf.nix b/xtensa-esp-elf.nix new file mode 100644 index 0000000..ba4662c --- /dev/null +++ b/xtensa-esp-elf.nix @@ -0,0 +1,37 @@ +{ + pkgs, + system, +}: let + systems_table = { + "x86_64-linux" = { + system = "x86_64-linux-gnu"; + hash = "sha256:1s86y3wss3vp5r6c076gz23hs62rkx1qc6vffjp42md86krrv1di"; + }; + }; + system_download = systems_table.${system}; +in + pkgs.stdenv.mkDerivation rec { + pname = "xtensa-esp-elf"; + version = "14.2.0_20241119"; + src = + builtins.fetchurl + { + url = "https://github.com/espressif/crosstool-NG/releases/download/esp-${version}/${pname}-${version}-${system_download.system}.tar.gz"; + sha256 = system_download.hash; + }; + + preferLocalBuild = true; + + nativeBuildInputs = with pkgs; [ + autoPatchelfHook + ]; + + buildInputs = with pkgs; [ + pkgs.stdenv.cc.cc + ]; + + installPhase = '' + mkdir -p "$out" + cp -R ./{bin,lib} "$out" + ''; + }