2

I want an udevrule to automatically mount usb sticks or sd-cards, if plugged into a terminal-computer. The way I tried to achieve this was adding an udevrule and make use of pmount's ability to mount devices as non root user.

The followig extraRule is defined in my configuration.nix:

services.udev.extraRules = ''
         ACTION=="add", SUBSYSTEM=="block", RUN+="${pkgs.bash}/bin/bash -c '${pkgs.pmount}/bin/pmount --sync --umask 000 %N &>> /tmp/udev-pmount.log'"
 '';

The error output in /tmp/udev-pmount.log is:

mount: /media/sdd2: permission denied.

The /media folder has 777 permissions and is empty

Executing the same command with sudo manually works by the way.

I have no idea how to get pmount and udev working correctly in NixOS to achieve that task.

Just for reference I add a link to automount.nix, where similar things should be achieved. But it does not work because KERNEL=="sd[a-z][0-9]" does not match anything.

1 Answer 1

2

Even though, the following solution is not a solution where pmount is involved, the following is the simple most udev automounting rule, that was able to automount storage in a reproducible manner.

services.udev.extraRules = ''
     ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", RUN{program}+="${pkgs.systemd}/bin/systemd-mount --no-block --automount=yes --collect $devnode /media"       
'';

The solution has been found within the arch wiki, which is mentioned in various answers concerning automount using udev.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .