[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to handle package udev rules?

From: Danny Milosavljevic
Subject: Re: How to handle package udev rules?
Date: Sun, 12 Dec 2021 19:17:26 +0100

Hello Alexander,

On Sun, 12 Dec 2021 13:12:50 +0100
Alexander Asteroth <> wrote:

> I tried to import the libgudev module but that that only results in the
> package wanting to write to another write-protected directory from the
> store.

It's supposed to write those to $output/lib/udev/rules.d (s.t. there's
*.rules inside) instead.   There's usually a cmake variable to make it do
that--but you need to look at the CMakeLists.txt in question.

Guix will pick those up if they originate in something it can see and add
those to Guix's udev service automatically (via the service extension mechanism,
which allows you to extend service config from outside the udev service).

Are you using Guix as an operating system? Or on top of another distribution?

> As I understand, the udev-rules are usually created on system level.


> That would mean I need to split the package into a service part
> and a package part? And remove the installation of the udev-file from
> the package install process?

Kinda not really--at least not exactly.  See below.

Example I'm using (that one definitely works--but I only add the custom
package because the upstream package doesn't do it![1]):

/etc/config.scm :

(define my-ledger-nano
    (name "my-ledger-nano")
    (version "1")
    (source #f)
    (build-system trivial-build-system)
    (synopsis "")
    (description "")
    (license #f)
    (home-page #f)
         (mkdir %output)
         (mkdir (string-append %output "/lib"))
         (mkdir (string-append %output "/lib/udev"))
         (mkdir (string-append %output "/lib/udev/rules.d"))
         (call-with-output-file (string-append %output 
           (lambda (port)
             (format port
"SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"2c97\", MODE=\"0600\", 
OWNER=\"dannym\", TAG+=\"uaccess\", TAG+=\"udev-acl\"
KERNEL==\"hidraw*\", ATTRS{idVendor}==\"2c97\", MODE=\"0600\", 
OWNER=\"dannym\", SYMLINK+=\"ledger_%n\", TAG+=\"uaccess\", TAG+=\"udev-acl\"

            (simple-service 'custom-udev-rules udev-service-type (list 
sane-backends my-ledger-nano)))

You can add your package reference there and it will work.

Or you can try adding your package reference into
  (operating-system (packages (list ...)))--should be enough.

If you mean adding your package's udev rules to the operating system
configuration without being the "root" user in-between: no, that would be a
(very bad! those rules run as root!) security problem.

In the case of your package, it seems[0] that they calculate the directory to
store the udev rules to from pkg-config--which will result in the udev
package's install directory. That won't work.

But in line 214 in [0] they seem to allow you to override it anyway.
So you can try to call cmake with


like this (in your package definition):

 '(#:configure-flags (list (string-append "-DCMAKE_INSTALL_UDEVRULESDIR="
                                          (assoc-ref %outputs "out")


Attachment: pgpbBV7TW5NMH.pgp
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]