unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Danny Milosavljevic <dannym@scratchpost.org>
To: Alexander Asteroth <alexander.asteroth@h-brs.de>
Cc: guix-devel@gnu.org
Subject: Re: How to handle package udev rules?
Date: Sun, 12 Dec 2021 19:17:26 +0100	[thread overview]
Message-ID: <20211212191711.43e4b7d2@scratchpost.org> (raw)
In-Reply-To: <878rwqf1s4.fsf@h-brs.de>

[-- Attachment #1: Type: text/plain, Size: 3478 bytes --]

Hello Alexander,

On Sun, 12 Dec 2021 13:12:50 +0100
Alexander Asteroth <alexander.asteroth@h-brs.de> 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.

Yes.

> 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
  (package
    (name "my-ledger-nano")
    (version "1")
    (source #f)
    (build-system trivial-build-system)
    (synopsis "")
    (description "")
    (license #f)
    (home-page #f)
    (arguments
     `(#:builder
       (begin
         (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 "/lib/udev/rules.d/99-my-ledger-nano.rules")
           (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\"
")))
         #t)))))

(operating-system
  ...
  (services
            (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

  -DCMAKE_INSTALL_UDEVRULESDIR=$output//lib/udev/rules.d

like this (in your package definition):

(package
  ...
  (arguments
 '(#:configure-flags (list (string-append "-DCMAKE_INSTALL_UDEVRULESDIR="
                                          (assoc-ref %outputs "out")
                                          "/lib/udev/rules.d"))))

[0] https://github.com/jahnf/Projecteur/blob/develop/CMakeLists.txt#L231
[1] https://github.com/LedgerHQ/udev-rules/pull/8

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2021-12-12 18:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-12 12:12 How to handle package udev rules? Alexander Asteroth
2021-12-12 13:57 ` Γυψ
2021-12-12 16:24 ` Tobias Geerinckx-Rice
2021-12-12 18:17 ` Danny Milosavljevic [this message]
2021-12-12 20:58   ` gyps
2021-12-12 22:37     ` Danny Milosavljevic
2021-12-13  8:48       ` Γυψ
2021-12-17  8:20         ` Alexander Asteroth
2021-12-17  9:08           ` Josselin Poiret via Development of GNU Guix and the GNU System distribution.
2022-01-04 22:38         ` SeerLite

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211212191711.43e4b7d2@scratchpost.org \
    --to=dannym@scratchpost.org \
    --cc=alexander.asteroth@h-brs.de \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).