Just to be transparent, I'm actually here to ask for help. My introduction sounds like an advertisement but I felt explaining the why would help avoid the "why not just X" kind of responses.
Why
Most of the context can be found here but I'll summarize it. I've been working on a system to build and deploy software for robots. It is based on Nix. Rosetta the Robot is my current working proof of concept.
Right now this system only supports deploying to targets that can run NixOS. I want to support deploying to Microcontrollers attached to systems running NixOS since these are typically used for more direct hardware interaction and are a frequent pain point for bringing up the software stack of robots. Every embedded workflow is different and I doubt I can make one to rule them all, so I chose to start my work with the Arduino platform since it's a rich, well maintained, and popular ecosystem. This will be more of a model of "how it should be done" for other embedded platforms to follow.
In order to deploy the software to the robot, I need to create two Nix derivations (packages). One of them is going to contain the ELF/HEX file to be flashed to the microcontroller. The other one will have the tool to upload the program to the microcontroller. Both of these need to be turned into a Nix derivation so they can be deployed to the robot via ssh or hard drive image generation.
The help I need
When building a Nix derivation, the internet cannot be accessed. This means that platform support packages, libraries, and the library/package index files cannot be downloaded during build. Nix needs to download and provide all of these ahead of time.
I have attempted to build a tool to solve this problem. It reads your sketch's scetch.yaml to find any referenced platforms, download their index files, download the archives for the requested platform, store those files into the nix store so they can be accessed during a build, and then generate a new sketch.yaml that references all of the downloaded packages.
This almost works! But I get the following errors when trying to build:
Downloading index: library_index.tar.bz2 Get "https://downloads.arduino.cc/libraries/library_index.tar.bz2": dial tcp: lookup downloads.arduino.cc on [::1]:53: read udp [::1]:51546->[::1]:53: read: connection refused
Error initializing instance: Error downloading index 'https://downloads.arduino.cc/libraries/library_index.tar.bz2': Get "https://downloads.arduino.cc/libraries/library_index.tar.bz2": dial tcp: lookup downloads.arduino.cc on [::1]:53: read udp [::1]:51546->[::1]:53: read: connection refused
Error initializing instance: Loading index file: loading json index file /homeless-shelter/.arduino15/package_index.json: open /homeless-shelter/.arduino15/package_index.json: no such file or directory
Downloading platform esp8266:esp8266@3.1.2 (file:///nix/store/habckxjcmgyv0isxnvk6d2bm9x9k3zm3-esp8266-3.1.2.zip)...
Downloading index: package_index.tar.bz2 Get "https://downloads.arduino.cc/packages/package_index.tar.bz2": dial tcp: lookup downloads.arduino.cc on [::1]:53: read udp [::1]:39904->[::1]:53: read: connection refused
Error downloading https://downloads.arduino.cc/packages/package_index.tar.bz2...
Error initializing instance: Error loading hardware platform: loading required platform esp8266:esp8266@3.1.2 (file:///nix/store/habckxjcmgyv0isxnvk6d2bm9x9k3zm3-esp8266-3.1.2.zip): Error downloading https://downloads.arduino.cc/packages/package_index.tar.bz2: Error downloading index 'https://downloads.arduino.cc/packages/package_index.tar.bz2': Get "https://downloads.arduino.cc/packages/package_index.tar.bz2": dial tcp: lookup downloads.arduino.cc on [::1]:53: read udp [::1]:39904->[::1]:53: read: connection refused
Error initializing instance: Error loading hardware platform: discovery builtin:serial-discovery not found
Error initializing instance: Error loading hardware platform: discovery builtin:mdns-discovery not found
Error initializing instance: Loading index file: reading library_index.json: open /homeless-shelter/.arduino15/library_index.json: no such file or directory
Error during build: Platform 'esp8266:esp8266' not found: platform not installed
There are a few errors here. I decided to tackle the first one which is to download library_index.tar.bz2. I could download that myself, parse the content of its provided library_index.json so I can download all the needed files into the nix store, and then write a modified version of that file into the Arduino config directory with all its URLs pointing into the Nix store. But then there's the library_index.json.sig. I'm not 100% sure but I think that's a cryptographic signature. It's not going to match my modified version of the index file, which means it will be rejected.
So... what can I do here? Is there a way tell arduino-cli to run in an "offline" mode so that only I can provide libraries? That sounds like the easiest answer to me.