I wrote a Nix package to install the libmonome software for manipulating a monome, which connects to the computer via USB. My libmonome
Nix package (that's a permanent link to the current unsatisfactory version) cannot access the device unless I use sudo
:
[jeff@jbb-dell:~]$ monomeserial
libmonome: could not open monome device: Permission denied
failed to open /dev/ttyUSB0
[jeff@jbb-dell:~]$ sudo monomeserial
[sudo] password for jeff:
monomeserial version 1.4.2, yay!
initialized device m0000102 (monome 256) at /dev/ttyUSB0, which is 16x16 using proto
mext
running with prefix /monome
^C
[jeff@jbb-dell:~]$
I can already use my USB printer from NixOS without using sudo
, so I strongly suspect this is possible. How can I modify the package so that running it with sudo
is unnecessary?
This is likely caused by the user that the application is running as not having permission to access the USB device. The clue is failed to open /dev/ttyUSB0
You may think that you have usb access because you can use printers and usb sticks, but these are accessed by daemons that do not run as your uid
To fix this, obtain the group of the USB device by running ls -l /dev/ttyUSB0
(replace with the name of your USB if different) and add this group to the list of secondary groups for the user that needs to access the device. You will need to log out and in for this modification to take effect.
There are security implications of this, since any USB can now be written, but its certainly a lot better than running the program via root via sudo. Consider the use of setgid
on the executible that performs the access if many users will need to run this, though this has other security issues.