Compare commits
12 Commits
05be1c4528
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d25704ee86 | |||
| b53c9c75cf | |||
| 2fe354b7eb | |||
|
|
cfa82ced5b | ||
|
|
d37e988cee | ||
|
|
dd6c6f4de7 | ||
|
|
6b092895be | ||
|
|
86e8139e45 | ||
|
|
4e0dc359f8 | ||
|
|
b213bf5bfb | ||
| fbdd609c0d | |||
| 2263f20c42 |
82
README.md
82
README.md
@@ -1,31 +1,22 @@
|
||||
# arduino-nix
|
||||
# arduino-sketch-builder-nix
|
||||
|
||||
A flake that allows building an `arduino-cli` environment with certain packages and libraries pre-installed.
|
||||
A flake that allows building Arduino sketches with nix.
|
||||
|
||||
This project is based on [arduino-nix](https://github.com/bouk/arduino-nix).
|
||||
|
||||
## Example
|
||||
|
||||
You need to provide a package index and library index to use `arduino-nix`. You can find some at [arduino-indexes](https://github.com/bouk/arduino-indexes).
|
||||
|
||||
Alternatively, you can download them at https://downloads.arduino.cc/packages/package_index.json and https://downloads.arduino.cc/libraries/library_index.json
|
||||
|
||||
From the indexes you create overlays which then make the Arduino packages and libraries available for the wrapArduinoCLI function provided by this flake.
|
||||
|
||||
```nix
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
arduino-nix.url = "github:bouk/arduino-nix";
|
||||
arduino-library-index = {
|
||||
url = "github:bouk/arduino-indexes/library_index";
|
||||
arduino-sketch-builder-nix.url = "git+https://git.clerie.de/clerie/arduino-sketch-builder-nix";
|
||||
arduino-index = {
|
||||
url = "github:bouk/arduino-indexes";
|
||||
flake = false;
|
||||
};
|
||||
arduino-package-index = {
|
||||
url = "github:bouk/arduino-indexes/package_index";
|
||||
flake = false;
|
||||
};
|
||||
arduino-package-rp2040-index = {
|
||||
url = "github:bouk/arduino-indexes/package_rp2040_index";
|
||||
arduino-esp32 = {
|
||||
url = "github:espressif/arduino-esp32/gh-pages";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
@@ -33,23 +24,18 @@ From the indexes you create overlays which then make the Arduino packages and li
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
arduino-nix,
|
||||
arduino-package-index,
|
||||
arduino-package-rp2040-index,
|
||||
arduino-library-index,
|
||||
arduino-sketch-builder-nix,
|
||||
arduino-index,
|
||||
arduino-esp32,
|
||||
...
|
||||
}@attrs:
|
||||
let
|
||||
overlays = [
|
||||
(arduino-nix.overlay)
|
||||
(arduino-nix.mkArduinoPackageOverlay (arduino-package-index + "/package_index.json"))
|
||||
(arduino-nix.mkArduinoPackageOverlay (arduino-package-rp2040-index + "/package_rp2040_index.json"))
|
||||
(arduino-nix.mkArduinoLibraryOverlay (arduino-library-index + "/library_index.json"))
|
||||
(arduino-nix.mkArduinoPackageOverlay (pkgs.fetchurl {
|
||||
url = "https://raw.githubusercontent.com/espressif/arduino-esp32/8bae7e23376c6087a55e46456049ae6d73b72e16/package_esp32_index.json";
|
||||
hash = "sha256-0kvZeRDtE/JKJes86omyN4cf4HWfX68P7xPfE+BvTC8=";
|
||||
}))
|
||||
(arduino-sketch-builder-nix.overlay)
|
||||
(arduino-sketch-builder-nix.mkArduinoPackageOverlay (arduino-index + "/index/package_index.json"))
|
||||
(arduino-sketch-builder-nix.mkArduinoPackageOverlay (arduino-index + "/index/package_rp2040_index.json"))
|
||||
(arduino-sketch-builder-nix.mkArduinoLibraryOverlay (arduino-index + "/index/library_index.json"))
|
||||
(arduino-sketch-builder-nix.mkArduinoPackageOverlay (arduino-esp32 + "/package_esp32_index.json"))
|
||||
];
|
||||
in
|
||||
(flake-utils.lib.eachDefaultSystem (system:
|
||||
@@ -61,11 +47,11 @@ From the indexes you create overlays which then make the Arduino packages and li
|
||||
# arduinoEnv provides bin/arduino-cli and some useful helpers functions
|
||||
arduinoEnv = pkgs.makeArduinoEnv {
|
||||
libraries = with pkgs.arduinoLibraries; [
|
||||
(arduino-nix.latestVersion ADS1X15)
|
||||
(arduino-nix.latestVersion Ethernet_Generic)
|
||||
(arduino-nix.latestVersion SCL3300)
|
||||
(arduino-nix.latestVersion TMCStepper)
|
||||
(arduino-nix.latestVersion pkgs.arduinoLibraries."Adafruit PWM Servo Driver Library")
|
||||
(arduino-sketch-builder-nix.latestVersion ADS1X15)
|
||||
(arduino-sketch-builder-nix.latestVersion Ethernet_Generic)
|
||||
(arduino-sketch-builder-nix.latestVersion SCL3300)
|
||||
(arduino-sketch-builder-nix.latestVersion TMCStepper)
|
||||
(arduino-sketch-builder-nix.latestVersion pkgs.arduinoLibraries."Adafruit PWM Servo Driver Library")
|
||||
];
|
||||
|
||||
packages = with pkgs.arduinoPackages; [
|
||||
@@ -100,18 +86,34 @@ From the indexes you create overlays which then make the Arduino packages and li
|
||||
src = ./. + "/my-esp32-poe-iso-project";
|
||||
fqbn = "esp32:esp32:esp32-poe-iso";
|
||||
};
|
||||
};
|
||||
|
||||
hydraJobs = {
|
||||
# Build binary tarball in CI
|
||||
my-esp32-poe-iso-project = my-esp32-poe-iso-project.binaryTarball;
|
||||
};
|
||||
}
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
## Interactive arduino-cli usage:
|
||||
### Package and library index
|
||||
|
||||
You need to provide a package index and library index. You can use [arduino-indexes](https://github.com/bouk/arduino-indexes) as a collection of common indexes. Accessing them via this git repo allows Nix Flakes to pin them as an input.
|
||||
|
||||
Alternatively, you can just download and check in the official Arduino indexes:
|
||||
- <https://downloads.arduino.cc/packages/package_index.json>
|
||||
- <https://downloads.arduino.cc/libraries/library_index.json>
|
||||
|
||||
### Interactive arduino-cli usage:
|
||||
|
||||
```
|
||||
nix develop .#arduinoEnv
|
||||
nix shell .#arduinoEnv
|
||||
```
|
||||
|
||||
## Build Arduino Sketch
|
||||
This adds a wrapped version of `arduino-cli` to your path that reflects you Arduino environment.
|
||||
|
||||
### Build Arduino Sketch
|
||||
|
||||
```
|
||||
nix build .#my-rp2040-project
|
||||
@@ -119,7 +121,7 @@ nix build .#my-rp2040-project
|
||||
|
||||
Now you have `result` in your current working directory containing the compile outputs.
|
||||
|
||||
## Upload to board
|
||||
### Upload to board
|
||||
|
||||
```
|
||||
nix run .#my-rp2040-project.uploadArduinoSketch -- -p /dev/ttyUSB0
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
let
|
||||
mkArduinoEnv = {
|
||||
packages
|
||||
, libraries
|
||||
packages ? []
|
||||
, libraries ? []
|
||||
, runtimeInputs ? []
|
||||
}: let
|
||||
arduino-cli = pkgs.wrapArduinoCLI {
|
||||
@@ -49,14 +49,34 @@ let
|
||||
inherit fqbn;
|
||||
arduinoSketch = (finalAttrs.finalPackage);
|
||||
};
|
||||
binaryTarball = binaryTarball {
|
||||
inherit name;
|
||||
arduinoSketch = (finalAttrs.finalPackage);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
uploadArduinoSketch = arduinoEnv: {
|
||||
arduinoSketch
|
||||
, fqbn
|
||||
}: pkgs.writeScriptBin "upload-arduino-sketch" ''
|
||||
}: pkgs.writeShellApplication {
|
||||
name = "upload-arduino-sketch";
|
||||
text = ''
|
||||
${arduinoEnv}/bin/arduino-cli upload --log --input-dir=${arduinoSketch} --fqbn=${fqbn} "$@"
|
||||
'';
|
||||
};
|
||||
|
||||
binaryTarball = {
|
||||
arduinoSketch
|
||||
, name
|
||||
}: pkgs.runCommand "binary-tarball" {} ''
|
||||
mkdir -p $out
|
||||
|
||||
cd ${arduinoSketch}
|
||||
${pkgs.gnutar}/bin/tar -czf $out/${name}.tar.gz *
|
||||
|
||||
mkdir -p $out/nix-support
|
||||
echo "file binary-dist $out/${name}.tar.gz" > $out/nix-support/hydra-build-products
|
||||
'';
|
||||
in
|
||||
mkArduinoEnv
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
description = "Wrapper for arduino-cli";
|
||||
description = "Build Arduino sketches";
|
||||
|
||||
outputs = { self }: {
|
||||
mkArduinoPackageOverlay = packageIndexFile: (self: super: {
|
||||
|
||||
6
lib.nix
6
lib.nix
@@ -27,9 +27,11 @@ with builtins; rec {
|
||||
else if system == "i686-darwin" then
|
||||
lib.findFirst ({host, ...}: (match "i[3456]86-apple-darwin.*" host) != null) null systems
|
||||
else if system == "aarch64-linux" then
|
||||
lib.findFirst ({host, ...}: (match "(aarch64|arm64)-linux-gnu" host) != null) null systems
|
||||
# tools.go uses regexp.MatchString which will also return true for substring matches, so we add a .* to the regex
|
||||
lib.findFirst ({host, ...}: (match "(aarch64|arm64)-linux-gnu.*" host) != null) null systems
|
||||
else if system == "x86_64-linux" then
|
||||
lib.findFirst ({host, ...}: (match "x86_64-.*linux-gnu" host) != null) null systems
|
||||
# also add a .* to the regex here though it is not necessary in the current dataset (March 2024)
|
||||
lib.findFirst ({host, ...}: (match "x86_64-.*linux-gnu.*" host) != null) null systems
|
||||
else null;
|
||||
convertHash = hash: let
|
||||
m = (match "(SHA-256|SHA-1|MD5):(.*)" hash);
|
||||
|
||||
@@ -19,7 +19,7 @@ let
|
||||
runHook postInstall
|
||||
'';
|
||||
nativeBuildInputs = [ pkgs.unzip ];
|
||||
src = fetchurl ({
|
||||
src = pkgs.fetchurl ({
|
||||
url = url;
|
||||
} // (convertHash checksum));
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ let
|
||||
cp -R * "$out/$dirName/"
|
||||
'';
|
||||
nativeBuildInputs = [ pkgs.unzip ];
|
||||
src = fetchurl ({
|
||||
src = pkgs.fetchurl ({
|
||||
url = system.url;
|
||||
} // (convertHash system.checksum));
|
||||
};
|
||||
@@ -58,7 +58,7 @@ let
|
||||
runHook postInstall
|
||||
'';
|
||||
nativeBuildInputs = [ pkgs.unzip ];
|
||||
src = fetchurl ({
|
||||
src = pkgs.fetchurl ({
|
||||
url = url;
|
||||
} // (convertHash checksum));
|
||||
};
|
||||
|
||||
@@ -22,6 +22,9 @@ let
|
||||
(pkgs.writeTextDir "package_index.json" (builtins.toJSON {packages = [];}))
|
||||
(pkgs.writeTextDir "library_index.json" (builtins.toJSON {libraries = [];}))
|
||||
];
|
||||
postBuild = ''
|
||||
mkdir -p $out/staging
|
||||
'';
|
||||
};
|
||||
in
|
||||
pkgs.runCommand "arduino-cli-wrapped" {
|
||||
|
||||
Reference in New Issue
Block a user