From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id UwAUJpTdHWW5YwEAG6o9tA:P1 (envelope-from ) for ; Wed, 04 Oct 2023 23:48:04 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id UwAUJpTdHWW5YwEAG6o9tA (envelope-from ) for ; Wed, 04 Oct 2023 23:48:04 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2B19E5925E for ; Wed, 4 Oct 2023 23:48:04 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=planete-kraus.eu header.s=albinoniB header.b="g QFNizI"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1696456084; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=1RN07+WLzVwL65vzrH7+24dHwHVboBV9bQMkcUfKHvA=; b=lbUu9TDlA36uU+hf2S2pTJRYPfK86tiT4oLVPe+iOzcZzYtB+wjv9/E2gbioeRkCz4Y5ul XQHAB2eE6y9LcUyYL6IHzYXi1PlviGyP0P3Jr8kGZ4dBUk7qGA/zTP38riIoOL3Azix/49 409HugKl+bgcae5QRVkEjiMJRtrHErxMAbCjMzV8E8kALOUSpOWxNX0bMROjA5cW0HHrW3 T+hAAWASBakzU7umqiH5G6RXDuC2ORV6SOqo+CGXDWZX3CnDI6pRwrLOFh0lNV5ghvcMGZ IZETTQwzEngTxUXt5eFvl0sXGXItSNmxFIeEwhqrFUPHg+G+jEOUv7tcf2DFtQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1696456084; a=rsa-sha256; cv=none; b=omddRKomeeLBN0WdyA5mSN/OEhMogopUMJJz+F+/qjhxQOr/mVerrqtVnwF1CjqMI/wxqN 1+Wd7IX75vswP8MnM+2v2+f8axVIPICaJga/Ca5tVvHzSe810FQDr/qegC+GZvn4H8FPdl aZQYFcE+cfxWO2I7vD5VNDeV9F32F0YufJSqiUuR2/S5FuwrGA3JHDI2PbHKbeSswo1R+/ Dkk2I8wK8Ug9eqj83qz/atZbZH+adPRWkS0noilTALHLCvWFuwV/EKgutrvvcydOZmV8cj 41anezNQfDkl7pbJtgqXaREZp8he1qdI8UD/cfl6/LQzDz2LsxXcystqC9MaIQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=planete-kraus.eu header.s=albinoniB header.b="g QFNizI"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo9ie-0007GV-66; Wed, 04 Oct 2023 17:47:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo9ia-0007EJ-Ql for guix-patches@gnu.org; Wed, 04 Oct 2023 17:47:45 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qo9ia-0000Iu-Fp for guix-patches@gnu.org; Wed, 04 Oct 2023 17:47:44 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qo9is-0005Ek-93 for guix-patches@gnu.org; Wed, 04 Oct 2023 17:48:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66099] [PATCH gnome-team v6 3/5] gnu: udev-service-type: accept hwdb file extensions. Resent-From: Vivien Kraus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 04 Oct 2023 21:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66099 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Liliana Marie Prikler , maxim.cournoyer@gmail.com, 66099@debbugs.gnu.org Cc: rg@raghavgururajan.name Received: via spool by 66099-submit@debbugs.gnu.org id=B66099.169645603119994 (code B ref 66099); Wed, 04 Oct 2023 21:48:02 +0000 Received: (at 66099) by debbugs.gnu.org; 4 Oct 2023 21:47:11 +0000 Received: from localhost ([127.0.0.1]:45498 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo9i2-0005CP-25 for submit@debbugs.gnu.org; Wed, 04 Oct 2023 17:47:10 -0400 Received: from planete-kraus.eu ([89.234.140.182]:37796) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qo9i0-0005CH-7b for 66099@debbugs.gnu.org; Wed, 04 Oct 2023 17:47:09 -0400 Received: from planete-kraus.eu (localhost.lan [127.0.0.1]) by planete-kraus.eu (OpenSMTPD) with ESMTP id 34e49650; Wed, 4 Oct 2023 21:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=planete-kraus.eu; h= message-id:in-reply-to:references:from:date:subject:to:cc :mime-version; s=albinoniB; bh=g00As9j+mbB2gC+pBiwBRbAQaCs=; b=g QFNizIeUkb8uXQnfn9SY4N6NfoKsrKyDvTQiG+o/h8doaHg5A61UEjiXjOf5D+9h DEvSr2I14AWrXWTYu/9XegfaoRdINACQ/ew6NkRaf9oeZWpux0xRW04sqg6cZh5v PNKhX5aH3Su1EwilRzKX+oLddsScKSTnkn6AzmXDnSd0E64RZxspx+4eNVh+bQ8A Kv2I/yqpB1JQDnrX/6eDwLZu5lPjAaP3hM542O+vqxRCIukXQ7tr98by3FnaFvUS UQLhJbRyixuohk9g+OmeMjosXUVAqEjJHpd+B+bAlLwqRMkGn0ltT/vUumdoJFOm OfWmZlptgk4xP4xHoCH0g== Received: by planete-kraus.eu (OpenSMTPD) with ESMTPSA id 65f24201 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Wed, 4 Oct 2023 21:46:49 +0000 (UTC) Message-ID: In-Reply-To: References: <42e4b490bce80a94f1afb7f5843d77823058150a.camel@gmail.com> Date: Mon, 2 Oct 2023 21:08:49 +0200 MIME-Version: 1.0 User-Agent: Evolution 3.46.4 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Vivien Kraus X-ACL-Warn: , Vivien Kraus via Guix-patches From: Vivien Kraus via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx0.migadu.com X-Migadu-Spam-Score: -1.23 X-Spam-Score: -1.23 X-Migadu-Queue-Id: 2B19E5925E X-TUID: z6AM93yw4w2G The "rules" field in the udev-configuration record can now hold both rules and hwdb files. The udev-rules-union has been made generic, and renamed to udev-configuration-union, so that it works with either rules or hwdb files. Some udev-related auxiliary functions in (gnu services base) had non-texinfo variable references in their docstrings ("FILE-NAME" instead of "@var{file-name}"). The contents of the /etc directory now includes hwdb.d and hwdb.bin, which is computed immediately. The documentation has been reworked so as to explain why creating udev rules or hwdb needs helper functions for configuration or extension. The hwdb.bin file is conditionally computed by a native version of eudev, that may be configured in the udev-service-type configuration. The condition is that both target and native eudev have the same version. If so, we can reasonably expect that the hwdb.bin file created by native eudev can later be read by target eudev. * gnu/services/base.scm (udev-configuration-union): Make udev-rules-union generic. (udev-hwdb): New function. (file->udev-rule): Fix docstring. (file->udev-hwdb): New function. (udev-rules-service): Fix docstring. (udev-hwdb-service): New function. (udev-etc): Add hwdb.d and hwdb.bin. (module): Export udev-hwdb, file->udev-hwdb, and udev-hwdb-service. (): Add the native-udev field. * doc/guix.texi (Base Services)[udev-service-type]: Explain configuration and extension values. * doc/guix.texi (Base Services)[udev-hwdb]: Document it. [udev-hwdb-service]: Same. * doc/guix.texi (Base Services)[udev-configuration]: Document the native-udev field. --- doc/guix.texi | 52 +++++++++++++++++++----- gnu/services/base.scm | 94 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 122 insertions(+), 24 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 46591b2f64..3310271ec8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19322,9 +19322,23 @@ Base Services @file{/dev} directory dynamically, whose value is a @code{} object. -This service type can be @emph{extended} using procedures -@code{udev-rules-service} along with @code{file->udev-rule} or -@code{udev-rule} which simplify the process of writing udev rules. +Since the file names for udev rules and hwdb files matters, the +configuration items for rules and hwdb cannot simply be plain file-like +objects with the rules content, because the name would be +ignored. Instead, they are directory file-like objects that contain +optional rules in @code{lib/udev/rules.d} and optional hwdb files in +@code{lib/udev/hwdb.d}. This way, the service can be configured with +whole packages from which to take rules and hwdb files. + +The @code{udev-service-type} can be @emph{extended} with file-like +directories that respect this hierarchy. However, to generate a +configuration or an extension, it is advised to use @code{udev-rule} and +@code{file->udev-rule} for rules, and @code{udev-hwdb} and +@code{file->udev-hwdb} for hwdb files. + +In an operating-system declaration, this service type can be +@emph{extended} using procedures @code{udev-rules-service} and +@code{udev-hwdb-service}. @end defvar @deftp {Data Type} udev-configuration @@ -19334,8 +19348,18 @@ Base Services @item @code{udev} (default: @code{eudev}) (type: file-like) Package object of the udev service. +@item @code{native-udev} (default: @code{eudev}) (type: file-like) +Native udev package to compile @code{hwdb.bin}. The trie format used for +@code{hwdb.bin} must be compatible with the @code{udev} and +@code{native-udev} fields of the udev configuration. To avoid generating +@code{hwdb.bin}, pass @code{#f} as the @code{native-udev} field. + +In any case, if the package version string differs between @code{udev} +and @code{native-udev}, @code{hwdb.bin} is @strong{not} created. + @item @code{rules} (default: @var{'()}) (type: list-of-file-like) -List of file-like objects denoting udev-rule files. +List of file-like objects denoting udev-rule or udev-hwdb files under a +sub-directory. @end table @end deftp @@ -19358,6 +19382,11 @@ Base Services @end lisp @end deffn +@deffn {Procedure} udev-hwdb @var{file-name} @var{contents} +Return a udev-hwdb file named @var{file-name} containing the hardware +information @var{contents}. +@end deffn + @deffn {Procedure} udev-rules-service @var{name} @var{rules} [#:groups '()] Return a service that extends @code{udev-service-type} with @var{rules} and @code{account-service-type} with @var{groups} as system groups. @@ -19377,6 +19406,11 @@ Base Services @end lisp @end deffn +@deffn {Procedure} udev-hwdb-service @var{name} @var{hwdb} +Return a service that extends @code{udev-service-type} with +@var{hwdb}. The service name is @code{@var{name}-udev-hwdb}. +@end deffn + @deffn {Procedure} file->udev-rule @var{file-name} @var{file} Return a udev-rule file named @var{file-name} containing the rules defined within @var{file}, a file-like object. @@ -19401,12 +19435,10 @@ Base Services @end lisp @end deffn -Additionally, Guix package definitions can be included in @var{rules} in -order to extend the udev rules with the definitions found under their -@file{lib/udev/rules.d} sub-directory. In lieu of the previous -@var{file->udev-rule} example, we could have used the -@var{android-udev-rules} package which exists in Guix in the @code{(gnu -packages android)} module. +@deffn {Procedure} file->udev-hwdb @var{file-name} @var{file} +Return a udev-hwdb file named @var{file-name} containing the rules +defined within @var{file}, a file-like object. +@end deffn The following example shows how to use the @var{android-udev-rules} package so that the Android tool @command{adb} can detect devices diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 190803b780..00916a35e4 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -81,6 +81,7 @@ (define-module (gnu services base) #:select (mount-flags->bit-mask swap-space->flags-bit-mask)) #:use-module (guix gexp) + #:use-module ((guix packages) #:select (package-version)) #:use-module (guix records) #:use-module (guix modules) #:use-module (guix pki) @@ -153,8 +154,11 @@ (define-module (gnu services base) udev-service-type udev-service ; deprecated udev-rule + udev-hwdb file->udev-rule + file->udev-hwdb udev-rules-service + udev-hwdb-service login-configuration login-configuration? @@ -2181,12 +2185,15 @@ (define-record-type* udev-configuration? (udev udev-configuration-udev ;file-like (default eudev)) - (rules udev-configuration-rules ;list of file-like + (native-udev udev-configuration-native-udev + (default eudev)) + (rules udev-configuration-rules ;list of rule- and + ;hwdb-providing packages (default '()))) -(define (udev-rules-union packages) - "Return the union of the @code{lib/udev/rules.d} directories found in each -item of @var{packages}." +(define (udev-configuration-union subdirectory packages) + "Return the union of the @code{lib/udev/@var{subdirectory}.d} directories found +in each item of @var{packages}." (define build (with-imported-modules '((guix build union) (guix build utils)) @@ -2197,7 +2204,8 @@ (define (udev-rules-union packages) (srfi srfi-26)) (define %standard-locations - '("/lib/udev/rules.d" "/libexec/udev/rules.d")) + '(#$(string-append "/lib/udev/" subdirectory ".d") + #$(string-append "/libexec/udev/" subdirectory ".d"))) (define (rules-sub-directory directory) ;; Return the sub-directory of DIRECTORY containing udev rules, or @@ -2208,15 +2216,21 @@ (define (udev-rules-union packages) (union-build #$output (filter-map rules-sub-directory '#$packages))))) - (computed-file "udev-rules" build)) + (computed-file (string-append "udev-" subdirectory) build)) (define (udev-rule file-name contents) "Return a directory with a udev rule file @var{file-name} containing @var{contents}." (file->udev-rule file-name (plain-file file-name contents))) +(define (udev-hwdb file-name contents) + "Return a directory with a udev hwdb file @var{file-name} containing +@var{contents}." + (file->udev-hwdb file-name (plain-file file-name contents))) + (define (file->udev-rule file-name file) - "Return a directory with a udev rule file FILE-NAME which is a copy of FILE." + "Return a directory with a udev rule file @var{file-name} which is a copy of +@var{file}." (computed-file file-name (with-imported-modules '((guix build utils)) #~(begin @@ -2231,6 +2245,23 @@ (define (file->udev-rule file-name file) (mkdir-p rules.d) (copy-file #$file file-copy-dest))))) +(define (file->udev-hwdb file-name file) + "Return a directory with a udev hwdb file @var{file-name} which is a copy of +@var{file}." + (computed-file file-name + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + + (define hwdb.d + (string-append #$output "/lib/udev/hwdb.d")) + + (define file-copy-dest + (string-append hwdb.d "/" #$file-name)) + + (mkdir-p hwdb.d) + (copy-file #$file file-copy-dest))))) + (define kvm-udev-rule ;; Return a directory with a udev rule that changes the group of /dev/kvm to ;; "kvm" and makes it #o660. Apparently QEMU-KVM used to ship this rule, @@ -2338,13 +2369,35 @@ (define udev.conf (define (udev-etc config) (match-record config - (udev rules) + (udev native-udev rules) + (let* ((hwdb.d + (udev-configuration-union "hwdb" (cons* udev rules))) + (hwdb.bin + (and native-udev + (equal? (package-version udev) + (package-version native-udev)) + (computed-file + "hwdb.bin" + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + (setenv "UDEV_HWDB_PATH" #$hwdb.d) + (invoke #+(file-append native-udev "/bin/udevadm") + "hwdb" + "--update" + "-o" #$output))))))) `(("udev" ,(file-union "udev" `(("udev.conf" ,udev.conf) ("rules.d" - ,(udev-rules-union (cons* udev kvm-udev-rule - rules))))))))) + ,(udev-configuration-union + "rules" + (cons* udev kvm-udev-rule + rules))) + ("hwdb.d" ,hwdb.d) + ,@(if hwdb.bin + `(("hwdb.bin" ,hwdb.bin)) + '())))))))) (define udev-service-type (service-type (name 'udev) @@ -2373,10 +2426,10 @@ (define-deprecated (udev-service #:key (udev eudev) (rules '())) (udev-configuration (udev udev) (rules rules)))) (define* (udev-rules-service name rules #:key (groups '())) - "Return a service that extends udev-service-type with RULES and -account-service-type with GROUPS as system groups. This works by creating a -singleton service type NAME-udev-rules, of which the returned service is an -instance." + "Return a service that extends udev-service-type with @var{rules} and +@code{account-service-type} with @var{groups} as system groups. This works by +creating a singleton service type @code{@var{name}-udev-rules}, of which the +returned service is an instance." (let* ((name (symbol-append name '-udev-rules)) (account-extension (const (map (lambda (group) @@ -2393,6 +2446,19 @@ (define* (udev-rules-service name rules #:key (groups '())) (description "This service adds udev rules.")))) (service type #f))) +(define (udev-hwdb-service name hwdb-files) + "Return a service that extends udev-service-type with @var{hwdb-files}, named +@code{@var{name}-udev-hwdb}." + (let* ((name (symbol-append name '-udev-hwdb)) + (udev-extension (const (list hwdb-files))) + (type (service-type + (name name) + (extensions (list + (service-extension + udev-service-type udev-extension))) + (description "This service adds udev hwdb files.")))) + (service type #f))) + (define (swap-space->shepherd-service-name space) (let ((target (swap-space-target space))) (symbol-append 'swap- -- 2.41.0