Platformio: Difference between revisions

The previous method doesn't wortk anymore; replaced by a reference to a working flake.
Mach50 (talk | contribs)
m Update the udev rules as per latest error messages from platformio. Use the `with pkgs;` nix style
 
(2 intermediate revisions by one other user not shown)
Line 3: Line 3:
== Basic development environment ==
== Basic development environment ==


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {} }:
let
let
in
in
   pkgs.mkShell {
   pkgs.mkShell {
     buildInputs = [
     buildInputs = with pkgs; [
       pkgs.platformio
       platformio
       # optional: needed as a programmer i.e. for esp32
       # optional: needed as a programmer i.e. for esp32
       # pkgs.avrdude
       avrdude
     ];
     ];
}
}
</syntaxHighlight>
</syntaxhighlight>


== NixOS ==
== NixOS ==
Line 20: Line 20:
Add the required udev rules.
Add the required udev rules.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{
{
   services.udev.packages = [  
   services.udev.packages = with pkgs; [  
     pkgs.platformio-core
     platformio-core.udev
     pkgs.openocd
     openocd
   ];
   ];
}
}
</syntaxHighlight>
</syntaxhighlight>


== Use in vscode ==
== Use in vscode ==
Line 42: Line 42:
[https://discourse.nixos.org/t/how-to-use-platformio-with-vscode/15805/3 As of PlatformIO IDE 2.0.0], <s>you will need a shell that allows the extension to run “python -m platformio” ([https://github.com/NixOS/nixpkgs/pull/237313 #237313])</s>:
[https://discourse.nixos.org/t/how-to-use-platformio-with-vscode/15805/3 As of PlatformIO IDE 2.0.0], <s>you will need a shell that allows the extension to run “python -m platformio” ([https://github.com/NixOS/nixpkgs/pull/237313 #237313])</s>:


Recently (2024?) simply building an FHS shell with the referred `nixpkgs` commit doesn't work anymore. The modification is probably incompatible with newer `nixpkgs`.
Recently (2024?) simply building an FHS shell with the referred <code>nixpkgs</code> commit doesn't work anymore. The modification is probably incompatible with newer <code>nixpkgs</code>.


There's a quick&dirty fix available as a <code>flake</code> <code>devShell</code>. For usage with <code>direnv</code> (recommended), make an <code>.envrc</code> in your project dir like this:<syntaxhighlight lang="bash">
There's a quick&dirty fix available as a <code>flake</code> <code>devShell</code>. For usage with <code>direnv</code> (recommended), make an <code>.envrc</code> in your project dir like this:<syntaxhighlight lang="bash">
Line 53: Line 53:
# https://github.com/direnv/direnv/issues/992
# https://github.com/direnv/direnv/issues/992
if [ -z "$IN_NIX_SHELL" ]; then
if [ -z "$IN_NIX_SHELL" ]; then
use flake $FLAKE\#pio-arduino-fhs
    use flake $FLAKE\#pio-arduino-fhs
fi
fi