kimb.dev

WebUSB on NixOS

Quansheng Fun

I got the urge to buy a Quansheng radio at Nix Camp. If you haven’t heard of it, a Quansheng UV-K5 is a cheap and very hackable ham radio. What’s cool is that you can now put the software to flash it inside a (Chromium) webpage with the WebUSB api. I also used a website with it to flash my Pixel 7 Pro with GrapheneOS. And flash my meshtastic radios with their firmware! Unfortunately, that didn’t quite work for me.

NixOS headache

It worked on my Mac with Google Chrome installed, but on my NixOS laptops, I stuck to Firefox… Luckily, Nix makes it easy to run a browser you don’t prefer.

nix run nixpkgs#chromium

But at least with my config, I had to use sudo to flash anything over a usb to serial connection. And Chromium refuses to start in a root environment, which is smart, but I was desperate.

After looking up my problem with “arch” on google, I found that you need your user to be part of the dialout group, which is pretty easy to do like so:

user.groups.dialout = ["YOUR_USERNAME"];

This was the issue all along. This also meant my CLI tools for serial flashing worked without root.

So did nix really have much to do with this?

Not really. But I really like that nix fixes are so concise and tractable. I would change this once on other distros and forget what fixed it, doomed to break on an update or reinstall, but now my git history says when I did a fix and how. This really annoyed me until I sorted it out, and I sat on making this blog post a few weeks. I would have forgotten with any other distro I’ve messed with.

And I’m liking this approach of looking into linux problems first generically, and then seeing how to nixify the fix. I’m no longer flailing until things work, I’m carefully building a configuration that works, and taking calculated retreats back to stability after weird experiments. I’ve never felt safer actually using linux and seeing how it’s structured, or had more fun learning how to get unstuck. It’s satisfying to follow a recipe, but just scary enough to be engaging when I have to fit it in my nix config. Maybe I’m just neurodivergent, though.

Reply to this post by email ↪