Building node extension modules at run-time

@zyga-snapd Again, I can’t as every device may end up having different services. This is btw a very common scenario for IoT…

Can you please explain why is it difficult to bundle all the binary modules any set of services needs? Unless your snap is a “node as a platform” and you want to deploy on top. In such case I’d say you should use node as a part and still build dedicated snaps that do specific things and are not a generic deployment platform.

As an analogy from distribution packaging: snap that allows you to install ubuntu and “apt install anything” is not a sane snap. Snap that bundles a specific package is sane as it is well-defined and scoped.

CC: @sergiusens any advice?

First of all, we are targeting hundrads of thousands and even millions of devices. Not every device is unique, but many are and will change over time. This should give you an idea of the management tooling required. We have such device management tooling today, which by the way supports many platforms apart from snap.

Node.js devices are all running Services developed using JavaScript which in turn may use npm packages. These are not part of the Snap, and are deployed at runtime from the Device Management tool. In most situations this is not a problem using Snap as all services are deployed to the $SNAP_DATA folder.

-However… some npm packages, such as SerialPort comes with C/C++ files that gets compiled at runtime…and then fails.

The problem is that some lib* files in the $SNAP directory are referencing other files in the /usr directory and don’t have access to them.

For more details: https://github.com/snapcore/snapcraft/issues/1605

Hi @wmmihaa
This could be to your interest
https://git.launchpad.net/~ondrak/ondras-snaps/+git/homebridge-snap/tree/snapcraft.yaml
it’s recipe for npm project, which allows run time npm module installation. Trick is to rebuild glibc from source and tell it it will live in different location. As core snap does not include all needed header files and dev dependencies needed for building, you need to include libc6-dev in your snap anyway. This will just build it from source, rather than using stage package , which allows us to alter prefix. With this trick npm install works just fine. I added also git, as some npm modules are installed from git.
Also remember to set all needed path correctly, you can see that here:
https://git.launchpad.net/~ondrak/ondras-snaps/+git/homebridge-snap/tree/scripts/bin/env-setup
You will notice that on permission side I have used docker interface. This is just to overcome lack of correct interface at the moment. I will try to work with @jdstrand to come up with more appropriate interface to cover this use case.

hope this will unblock your use case