Programatically (Github Actions) add udev rule to config file

I am trying to programmatically add a udev rule to a balena config installed inside an image.

The context is the same as here: Nvpmodel not installed on Jetson TX2 yocto image - setting the Jetson’s power mode without having to manually adjust every device.

I found the balena config write and balena config read calls, but I struggle to set the os.udevrules.101 field.

My desired config.json snippet looks like this:

{
  "applicationName": "Development",
...
  "os": {
    "udevRules": {
      "101": "ACTION==\"add\", SUBSYSTEMS==\"usb\", RUN+=\"/usr/sbin/nvpmodel -m 0\"\n"
    }
  }
}

When I manually create this file and then balena config inject it this works of course (see above link) and I can read it out using balena os read I get:

...
os:
  udevRules:
    101:
      """
        ACTION=="add", SUBSYSTEMS=="usb", RUN+="/usr/sbin/nvpmodel -m 0"

      """

What does NOT work is just setting the os.udevRules.101field with:

balena config write --type some_type --drive some_drive.img os.udevRules.101 "ACTION==\"add\", SUBSYSTEMS==\"usb\", RUN+=\"/usr/sbin/nvpmodel -m 0\""

That command succeeds, but balena config reads as:

...
s:
  udevRules:
    - null
    - null
    ...  a few 10s of these ...
    - null
  - ACTION=="add", SUBSYSTEMS=="usb", RUN+="/usr/sbin/nvpmodel -m 0"

So at least the 101 field does not seem to parse correctly.

Any suggestions on how to balena config write this data?

Thanks for reporting this issue, @rapha. The following pull request should fix the parsing of keys with numeric components: config write: Fix parsing of 'key' argument with numeric components by pdcastro · Pull Request #2291 · balena-io/balena-cli · GitHub
I need to write a few test cases before getting it merged – it will happen soon.

1 Like

The issue with balena config write ... os.udevRules.101 was fixed in CLI release v12.44.24 (or later). Thanks again for reporting it. :+1:

Thank you for the quick implementation. I can confirm that this works now.