[Question] On defining udev rules in system configuration

2023-09-17 Thread Rodrigo Morales
* The problem

I've defined the following udev-rule in my configuration (full
configuration attached)

#+BEGIN_SRC scheme
(... some omitted lines ...)

  (udev-service-type
config =>
(udev-configuration
 (inherit config)
 ;; SEE: 
https://unix.stackexchange.com/questions/459874/udev-doesnt-want-to-run-chgrp-and-chmod
 (rules
  `(,(udev-rule
  "90-backlight.rules"
  (string-append
   "ACTION==\"add\","
   "SUBSYSTEM==\"backlight\","
   "RUN+=\"/run/current-system/profile/bin/chgrp video
/sys/class/backlight/intel_backlight/brightness\""
   "\n"
   ))
,@(udev-configuration-rules config)

(... some omitted lines ...)
#+END_SRC

This made it possible to change the gorup for the file (see proof below)

#+BEGIN_SRC sh
ls -l /sys/class/backlight/intel_backlight/brightness
#+END_SRC

#+RESULTS:
#+BEGIN_EXAMPLE
-rw-r--r-- 1 root video 4096 Sep 17 20:48
/sys/class/backlight/intel_backlight/brightness
#+END_EXAMPLE

I'm user =rdrg= (see proof below)

#+BEGIN_SRC sh
whoami
#+END_SRC

#+RESULTS:
#+begin_example
rdrg
#+end_example

I belong to group =video= (see proof below)

#+BEGIN_SRC sh
cat /etc/group
#+END_SRC

#+RESULTS:
#+begin_example
root:x:0:
wheel:x:999:rdrg,rdrg-experiments
users:x:998:
nogroup:x:997:
tty:x:996:
dialout:x:995:
kmem:x:994:
input:x:993:
video:x:992:rdrg,rdrg-experiments,gdm
audio:x:991:rdrg,rdrg-experiments
netdev:x:990:rdrg,rdrg-experiments
lp:x:989:
disk:x:988:
floppy:x:987:
cdrom:x:986:
tape:x:985:
kvm:x:984:guixbuilder01,guixbuilder02,guixbuilder03,guixbuilder04,guixbuilder05,guixbuilder06,guixbuilder07,guixbuilder08,guixbuilder09,guixbuilder10
guixbuild:x:3:guixbuilder01,guixbuilder02,guixbuilder03,guixbuilder04,guixbuilder05,guixbuilder06,guixbuilder07,guixbuilder08,guixbuilder09,guixbuilder10
messagebus:x:983:
polkitd:x:982:
geoclue:x:981:
colord:x:980:
avahi:x:979:
scanner:x:978:
gdm:x:977:
sshd:x:976:
#+end_example

But I can't edit that file as a regular user (see proof below)

#+BEGIN_SRC sh
echo 0 > /sys/class/backlight/intel_backlight/brightness
echo Exit code: $?
#+END_SRC

#+RESULTS:
#+BEGIN_EXAMPLE
bash: /sys/class/backlight/intel_backlight/brightness: Permission denied
Exit code: 1
#+END_EXAMPLE

It is worth mentioning that I can edit that file as =sudo=

#+BEGIN_SRC sh
echo 0 | sudo tee /sys/class/backlight/intel_backlight/brightness
echo Exit code: $?
#+END_SRC

#+RESULTS:
#+BEGIN_EXAMPLE
0
Exit code: 0
#+END_EXAMPLE

* The questions

1. Why can't I edit =/sys/class/backlight/intel_backlight/brightness=
even though the file belongs to the =video= group?
2. What's the proper way to make it possible to edit
=/sys/class/backlight/intel_backlight/brightness=? I need to do this
because I want to define a keybinding in my windows manager that
changes the brightness.
(use-modules (gnu))

(use-service-modules
 networking
 ssh
 avahi
 ;; sddm-service-type
 sddm
 ;; gdm-service-type
 xorg
 ;; %desktop-services
 desktop)

(use-package-modules
 ssh
 certs)

(define %my-services
  ;; We need to modify the service. Otherwise, we get the following
  ;; error
  ;;
  ;; guix system: error: service 'guix-daemon' provided more than once
  (modify-services
   %desktop-services
   (delete gdm-service-type)
   (guix-service-type
config =>
(guix-configuration
 (inherit config)
 (discover? #t)
 (authorized-keys
  (append (list (local-file "./public-keys/delta.pub"))
  %default-authorized-guix-keys
   (udev-service-type
config =>
(udev-configuration
 (inherit config)
 ;; SEE: https://unix.stackexchange.com/questions/459874/udev-doesnt-want-to-run-chgrp-and-chmod
 (rules
  `(,(udev-rule
  "90-backlight.rules"
  (string-append
   "ACTION==\"add\","
   "SUBSYSTEM==\"backlight\","
   "RUN+=\"/run/current-system/profile/bin/chgrp video /sys/class/backlight/intel_backlight/brightness\""
   "\n"))
,@(udev-configuration-rules config)))

(operating-system
 (host-name "sony")
 (locale "en_US.utf8")
 (timezone "America/Lima")
 (bootloader
  (bootloader-configuration
   (bootloader grub-efi-bootloader)
   (targets '("/boot/efi"
 (file-systems
  (cons*
   (file-system
(device (file-system-label "my-efi"))
(mount-point "/boot/efi")
(type "vfat"))
   (file-system
(device (file-system-label "my-root"))
(mount-point "/")
(type "ext4"))
   (file-system
(device (file-system-label "my-home"))
(mount-point "/home")
(type "ext4"))
   %base-file-systems))
 (users
  (cons
   (user-account
(name "rdrg")
(comment "This is a comment for user rdrg")
(group "users")
(supplementary-groups
 '(;; Make the user a sudoer
   "wheel"
   ;; Allow the user to play sound
   "audio"
   ;; Allow the user to access the webcam
   "video")))
   %base-user-accounts))
 ;; Globally-installed packages
 (packages
  (cons*
   ;; This is mandatory. Otherw

Re: [Question] On defining udev rules in system configuration

2023-09-17 Thread Rodrigo Morales
Solved! I had to also run =chmod= (see complete configuration for
=udev-service-type= below)

#+BEGIN_SRC scheme
(udev-service-type
 config =>
 (udev-configuration
  (inherit config)
  (rules
   `(,(udev-rule
   "90-backlight.rules"
   (string-append
"ACTION==\"add\","
"SUBSYSTEM==\"backlight\","
"RUN+=\"/run/current-system/profile/bin/chgrp video
/sys/class/backlight/intel_backlight/brightness\""
"\n"
"ACTION==\"add\","
"SUBSYSTEM==\"backlight\","
"RUN+=\"/run/current-system/profile/bin/chmod g+w
/sys/class/backlight/intel_backlight/brightness\""))
 ,@(udev-configuration-rules config)
#+END_SRC



Re: [Question] On defining udev rules in system configuration

2023-09-17 Thread Felix Lechner via
Hi Rodrigo,

On Mon, Sep 18 2023, Rodrigo Morales wrote:

> I've defined the following udev-rule in my configuration

You are lucky your rule works! [1] Does udevadm find your rule?

Kind regards
Felix

[1] https://issues.guix.gnu.org/63508#3



Re: [Question] On defining udev rules in system configuration

2023-09-17 Thread Rodrigo Morales
Could you tell me what's the complete command that you are referring
to? I'm not very familiar with udevadm.

On Mon, 18 Sept 2023 at 02:44, Felix Lechner  wrote:
>
> Hi Rodrigo,
>
> On Mon, Sep 18 2023, Rodrigo Morales wrote:
>
> > I've defined the following udev-rule in my configuration
>
> You are lucky your rule works! [1] Does udevadm find your rule?
>
> Kind regards
> Felix
>
> [1] https://issues.guix.gnu.org/63508#3