nixpkgs-esp-dev icon indicating copy to clipboard operation
nixpkgs-esp-dev copied to clipboard

ESP-IDF for vscode cannot find /tools/idf.py in the nix store

Open Azeirah opened this issue 1 year ago • 8 comments

image

I'm trying to set-up vscodium with the ESP-IDF plugin to do esp development, but as you can see it's not quite working.

I think the issue might have to do with permissions?

Anyone have an idea how I can get the ESP-IDF plugin for VSCode(ium) to work on Nix?

Azeirah avatar Sep 22 '24 20:09 Azeirah

Hmm.. Even though the set-up is complaining, I can in fact use most (if not all?) of the tools in the ESP IDF vscodium plugin.

I am able to build, monitor from the plugin UI. I haven't been able to set-up flash, but that's due to openocd config issues that I haven't figured out yet (exporting like the other open issue said wasn't enough).

I'm still exploring the ESP development environment, so I'll keep this issue open as a starting point for conversation about the plugin as well as a point of reference for what I have and have not been able to get working.

  • I had to make sure to add my user to the dialout group. In my Nix configuration, I added dialout to my user's extraGroups list. I found the missing group with stat -c '%G' /dev/ttyUSB0.

IDE exploration

  • [x] I am able to set an espressif target
  • [x] I am able to build
  • [ ] I am unable to flash (but I can use idf.py provided by this project manually, so it's ok)
  • [x] I am able to monitor
  • [x] I am able to erase flash
  • [x] I am able to use the EFUSEEXPLORER window.
  • [ ] ...? Haven't explored further yet. I'll update the issue as I explore more.

Azeirah avatar Sep 22 '24 21:09 Azeirah

Oh and for reference, I made a flake that combines this project with the vscodium flake. I have to be honest, I let claude do most of it. I'm still learning Nix. For what it's worth, it does work. It gives you a vscodium installation with ESP-IDF pre-installed, so it's practically a portable development environment nixified.

If anyone is interested in trying (or roasting the flake, I'm sorry!) feel free to comment :)

{
  description = "ESP-IDF development environment with VSCodium";

  inputs = {
    nixpkgs.url = "nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
    esp-dev.url = "github:mirrexagon/nixpkgs-esp-dev";
  };

  outputs = { self, nixpkgs, flake-utils, nix-vscode-extensions, esp-dev }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [
            esp-dev.overlays.default
            nix-vscode-extensions.overlays.default
          ];
        };

        extensions = pkgs.vscode-marketplace;

        vscodium-with-extensions = pkgs.vscode-with-extensions.override {
          vscode = pkgs.vscodium;
          vscodeExtensions = [
            extensions.golang.go
            extensions.rust-lang.rust-analyzer
	     extensions.espressif.esp-idf-extension
          ];
        };

      in {
        packages = {
          default = vscodium-with-extensions;
          inherit (pkgs) esp-idf-full;
        };

        devShells.default = pkgs.mkShell {
          buildInputs = [
            vscodium-with-extensions
            pkgs.esp-idf-full
          ];

          shellHook = ''
            alias i='idf.py'

            printf "\033[1;36m"  # Set text color to cyan
            cat << EOF
            ╔════════════════════════════════════════════════════════════════╗
            ║         Welcome to the ESP-IDF Development Environment!        ║
            ╚════════════════════════════════════════════════════════════════╝

            This environment provides you with:

            1. VSCodium with pre-configured extensions for ESP-IDF development
               - Run 'codium' to start the IDE

            2. ESP-IDF tools, including idf.py (aliased to 'i')
               - Run 'i' or 'idf.py' to use the ESP-IDF build system

            To get started with ESP-IDF, visit:
            https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/index.html

            Here's a quick overview of what's available:
            EOF
            printf "\033[0m"  # Reset text color

            printf "\033[1;33m"  # Set text color to yellow
            printf "\nVSCodium with extensions:\n"
            codium --list-extensions
            printf "\033[0m"  # Reset text color

            printf "\033[1;32m"  # Set text color to green
            printf "\nESP-IDF environment:\n"
            i --version
            printf "\033[0m"  # Reset text color

            printf "\n\033[1mTip:\033[0m You can use 'i' as a shortcut for 'idf.py'. For example:\n"
            printf "  i build\n"
            printf "  i flash\n"
            printf "  i monitor\n"

            printf "\n\033[1mHappy coding with ESP-IDF!\033[0m\n"
          '';
	};
      }
    );
}

Azeirah avatar Sep 22 '24 21:09 Azeirah

Search for documentation feature does not work:

image

This is a desirable feature, so I'll have to find a workaround for it.

Azeirah avatar Sep 22 '24 21:09 Azeirah

I also have this problem. I'm just running nix --experimental-features 'nix-command flakes' develop github:mirrexagon/nixpkgs-esp-dev#esp32c6-idf and then code . in the resulting shell to try and get everything into vscode.

arulagrawal avatar Feb 12 '25 13:02 arulagrawal

I also have this problem, from both the use flake method and the standalone shell.nix

johnbarnes-vi avatar Mar 12 '25 19:03 johnbarnes-vi

I also had this problem when trying to use the extension yesterday. I think I've figured out what's going on here. Looking at the output of running the ESP IDF: Doctor Command is VS Code, I see lines similar to

{"message":"Cannot access filePath: /nix/store/szjw0aqa9djvn285szvk2911mdh9ssa8-esp-idf-v5.4.1/tools/idf.py","stack":"Error: EACCES: permission denied, access '/nix/store/szjw0aqa9djvn285szvk2911mdh9ssa8-esp-idf-v5.4.1/tools/idf.py'

That line's being logged by this function in the ESP IDF extension codebase. The validation added in this commit checks that the extension has write access to idf.py. Of course, it doesn't since files in /nix/store/ are read/execute only.

I can submit a small PR to update that validation logic. I'm relatively new to Nix, so I don't know whether there's a Nix idiomatic way of handling misbehaving applications like this as a workaround. Anyone have any pointers?

jonsambro avatar Jul 01 '25 16:07 jonsambro

My change was merged so this issue should be fixed in ESP IDF VSCode Extension v1.11.0+.

jonsambro avatar Jul 20 '25 16:07 jonsambro

Issue still exists on ESP IDF VSCode Extension v2.0.1

Command failed: /nix/store/x6sc9qfsz5ki13s9faaiblwg3js78ma8-python3-3.12.11-env/bin/python3 /nix/store/3kwgdiamcz3g9z6889bir2lqp0sd6paz-esp-idf-v5.5.1/tools/idf_tools.py export --format key-value
ERROR: tool esp-rom-elfs has no installed versions. The environment indicates that you might be using NixOS. Please see https://nixos.wiki/wiki/ESP-IDF for how to install tools for it.

while i was using flake:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    esp-dev.url = "github:mirrexagon/nixpkgs-esp-dev";
  };

  outputs = {
    self,
    nixpkgs,
    esp-dev,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (
      system: let
        pkgs = import nixpkgs {
          inherit system;
          config.permittedInsecurePackages = [
            "python3.13-ecdsa-0.19.1"
          ];
        };
      in {
        devShells = rec {
          default = pkgs.mkShell {
            name = "esp-idf-full-shell";

            buildInputs = with pkgs;
              [
                just
                minicom
                usbutils
              ]
              ++ [
                esp-dev.packages.${system}.esp-idf-full
              ];
            shellHook = ''
              export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib.outPath}/lib:$LD_LIBRARY_PATH";
            '';
          };
        };
      }
    );
}

jaanonim avatar Nov 07 '25 10:11 jaanonim