From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id QKLlLbmxWGB3QQAA0tVLHw (envelope-from ) for ; Mon, 22 Mar 2021 15:03:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id MDDLKbmxWGCUZgAAbx9fmQ (envelope-from ) for ; Mon, 22 Mar 2021 15:03:21 +0000 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 E4BEBF5F2 for ; Mon, 22 Mar 2021 16:03:20 +0100 (CET) Received: from localhost ([::1]:35186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOM5P-0004uJ-FL for larch@yhetil.org; Mon, 22 Mar 2021 11:03:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOLe2-0000gC-RC for guix-patches@gnu.org; Mon, 22 Mar 2021 10:35:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOLe2-0006fP-J3 for guix-patches@gnu.org; Mon, 22 Mar 2021 10:35:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lOLe2-0001wM-FF for guix-patches@gnu.org; Mon, 22 Mar 2021 10:35:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#45692] [PATCH v3 1/3] gnu: Allow services to install kernel-loadable modules. References: In-Reply-To: Resent-From: raid5atemyhomework Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 22 Mar 2021 14:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45692 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: "45692@debbugs.gnu.org" <45692@debbugs.gnu.org> Received: via spool by 45692-submit@debbugs.gnu.org id=B45692.16164236437374 (code B ref 45692); Mon, 22 Mar 2021 14:35:02 +0000 Received: (at 45692) by debbugs.gnu.org; 22 Mar 2021 14:34:03 +0000 Received: from localhost ([127.0.0.1]:58240 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOLcz-0001uM-5P for submit@debbugs.gnu.org; Mon, 22 Mar 2021 10:34:03 -0400 Received: from mail-40137.protonmail.ch ([185.70.40.137]:18535) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOLcw-0001u8-Uk for 45692@debbugs.gnu.org; Mon, 22 Mar 2021 10:33:56 -0400 Date: Mon, 22 Mar 2021 14:33:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1616423627; bh=nC0SrT1UUqmuzzJcLCVexazP+FJ9FVBa+IiJp76WntA=; h=Date:To:From:Reply-To:Subject:From; b=D6Mp92VTvJjiM0x7mwj3F8aFsiOspXJJRoSLGUHqyeGmuENEI/RP9FdnFggNGDeuy 2lzda1PvhpTTzqQoRgo03PfZ+GpHL4usBHKOKuYZPeM63SP05Vdj4WFPwF12mBJ1jC bPS6JiZoSHErd8f1wp/FMCYPlPCnaobRW1whkplE= Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: raid5atemyhomework X-ACL-Warn: , raid5atemyhomework via Guix-patches From: raid5atemyhomework via Guix-patches via X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1616425401; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: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=nC0SrT1UUqmuzzJcLCVexazP+FJ9FVBa+IiJp76WntA=; b=ry1TwFo63i1LzKM923mUrBIoojqS0xC+6QmURfZ3HlbPK28dzmgv3s0FfC6dSQaw970kgm 1G8lBQvw0c63mYWNlxidA8jNbyrhx5jFacMWr85awAXq+qbJXUkKzwGgEkZrmgBmYIp8Zy aIY1BWEpHeFxllw2wN7oFFfXWOMN2uEFBw31/jo6vHx4e8DHqtY+Tsw852Uty1ljnWy2QH ysBeJ+TnGRD+TqrqDidkCwblxUqo6wYLqF/oFNgIIB0WYpXxQdddR+McTclHCbuZxBKgLt b5tMs3ehdT/r6r4uz9xcwfmpjPrHk847YsDmrH7we1HZcDVagxP5la3Fq7GwQQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616425401; a=rsa-sha256; cv=none; b=ilptW7TQfkhDtJpfy2ivzbE2Fb/H6ZpteDTACO8i8fSeYNs6OaVP5A5ve7lD4LknXUcqj0 gRWczZv1jrYe9EetHZofvjzDAwGsNFu7guw+h4BHi5jhO+eX109ShdpjCYTmu1p9ksh1w5 fpI4DgWONWoc8Mz2RF6pfLlKEhLkw8i/r+fZp6beFW4wBMOGcx6FAxBUhg1Ex5onuaJAEp iP8DdIgA3AScmU/RRIWaZ9VKfq4JzZZR9MAKTNBl2BH8g83tIUbFXZlDNlVI2FetSfKJxw 7qwlXnB6uIn3Oplq+xZGQ6vFKPE0J2ocaLCab1tfGZlu6/Ua/4AI7PY5EiFvqw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=protonmail.com header.s=protonmail header.b=D6Mp92VT; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -2.92 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=protonmail.com header.s=protonmail header.b=D6Mp92VT; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: E4BEBF5F2 X-Spam-Score: -2.92 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9936hmVE9aXk >From d54d718dd83195041d9f536e8c675eb2bffdcb8d Mon Sep 17 00:00:00 2001 From: raid5atemyhomework Date: Mon, 22 Mar 2021 11:23:32 +0800 Subject: [PATCH 1/3] gnu: Allow services to install kernel-loadable modules= . * gnu/system.scm (operating-system-directory-base-entries): Remove code to handle generation of "kernel" for linux-libre kernels. (operating-system-default-essential-services): Instantiate linux-builder-service-type. (package-for-kernel): Move ... * gnu/services.scm: ... to here. (linux-builder-service-type): New variable. (linux-builder-configuration): New type. (linux-loadable-module-service-type): New variable. * gnu/tests/linux-modules.scm (run-loadable-kernel-modules-test): Move code to ... (run-loadable-kernel-modules-test-base): ... new procedure here. (run-loadable-kernel-modules-service-test): New procedure. (%test-loadable-kernel-modules-service-0): New variable. (%test-loadable-kernel-modules-service-1): New variable. (%test-loadable-kernel-modules-service-2): New variable. * doc/guix.texi: Document linux-loadable-module-service-type. --- doc/guix.texi | 22 +++++++++ gnu/services.scm | 90 +++++++++++++++++++++++++++++++++++++ gnu/system.scm | 34 ++++---------- gnu/tests/linux-modules.scm | 80 ++++++++++++++++++++++++++++----- 4 files changed, 191 insertions(+), 35 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 386169b2a5..86b22f3673 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -33967,6 +33967,28 @@ configuration when you use @command{guix system re= configure}, @command{guix system init}, or @command{guix deploy}. @end defvr +@defvr {Scheme Variable} linux-loadable-module-service-type +Type of the service that collects lists of packages containing +kernel-loadable modules, and adds them to the set of kernel-loadable +modules. + +This service type is intended to be extended by other service types, +such as below: + +@lisp +(define module-installing-service-type + (service-type + (name 'module-installing-service) + (extensions (list (service-extension linux-loadable-module-service-typ= e + (const (list module-to-install-1 + module-to-install-2)= )))) + (default-value #f))) +@end lisp + +This does not actually load modules at bootup, only adds it to the +kernel profile so that it @emph{can} be loaded by other means. +@end defvr + @node Shepherd Services @subsection Shepherd Services diff --git a/gnu/services.scm b/gnu/services.scm index ddd1bac30c..a20edeb8ec 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -2,6 +2,7 @@ ;;; Copyright =C2=A9 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Court= =C3=A8s ;;; Copyright =C2=A9 2016 Chris Marusich ;;; Copyright =C2=A9 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright =C2=A9 2021 raid5atemyhomework ;;; ;;; This file is part of GNU Guix. ;;; @@ -33,6 +34,8 @@ #:use-module (guix diagnostics) #:autoload (guix openpgp) (openpgp-format-fingerprint) #:use-module (guix modules) + #:use-module (guix packages) + #:use-module (guix utils) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages hurd) @@ -106,6 +109,12 @@ profile-service-type firmware-service-type gc-root-service-type + linux-builder-service-type + linux-builder-configuration + linux-builder-configuration? + linux-builder-configuration-kernel + linux-builder-configuration-modules + linux-loadable-module-service-type %boot-service %activation-service @@ -872,6 +881,87 @@ as Wifi cards."))) will not be reclaimed by the garbage collector.") (default-value '()))) +;; Configuration for the Linux kernel builder. +(define-record-type* + linux-builder-configuration + make-linux-builder-configuration + linux-builder-configuration? + this-linux-builder-configuration + + (kernel linux-builder-configuration-kernel) ; packag= e + (modules linux-builder-configuration-modules (default '()))) ; list o= f packages + +(define (package-for-kernel target-kernel module-package) + "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if +possible (that is if there's a LINUX keyword argument in the build system)= ." + (package + (inherit module-package) + (arguments + (substitute-keyword-arguments (package-arguments module-package) + ((#:linux kernel #f) + target-kernel))))) + +(define (linux-builder-configuration->system-entry config) + "Return the kernel entry of the 'system' directory." + (let* ((kernel (linux-builder-configuration-kernel config)) + (modules (linux-builder-configuration-modules config)) + (kernel (profile + (content (packages->manifest + (cons kernel + (map (lambda (module) + (cond + ((package? module) + (package-for-kernel kernel m= odule)) + ;; support (,package "kernel-= module-output") + ((and (list? module) (package= ? (car module))) + (cons (package-for-kernel ke= rnel + (c= ar module)) + (cdr module))) + (else + module))) + modules)))) + (hooks (list linux-module-database))))) + (with-monad %store-monad + (return `(("kernel" ,kernel)))))) + +(define linux-builder-service-type + (service-type (name 'linux-builder) + (extensions + (list (service-extension system-service-type + linux-builder-configuration->sy= stem-entry))) + (default-value '()) + (compose identity) + (extend (lambda (config modifiers) + (if (null? modifiers) + config + ((apply compose modifiers) config)))) + (description "Builds the linux-libre kernel profile, conta= ining +the kernel itself and any linux-loadable kernel modules. This can be exte= nded +with a function that accepts the current configuration and returns a new +configuration."))) + +(define (linux-loadable-module-builder-modifier modules) + "Extends linux-builder-service-type by appending the given MODULES to th= e +configuration of linux-builder-service-type." + (lambda (config) + (linux-builder-configuration + (inherit config) + (modules (append (linux-builder-configuration-modules config) + modules))))) + +(define linux-loadable-module-service-type + (service-type (name 'linux-loadable-modules) + (extensions + (list (service-extension linux-builder-service-type + linux-loadable-module-builder-m= odifier))) + (default-value '()) + (compose concatenate) + (extend append) + (description "Adds packages and package outputs as modules +included in the booted linux-libre profile. Other services can extend thi= s +service type to add particular modules to the set of linux-loadable module= s."))) + + =0C ;;; ;;; Service folding. diff --git a/gnu/system.scm b/gnu/system.scm index 5bf2a85272..7cc4f134b7 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -13,6 +13,7 @@ ;;; Copyright =C2=A9 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright =C2=A9 2020 Efraim Flashner ;;; Copyright =C2=A9 2021 Maxime Devos +;;; Copyright =C2=A9 2021 raid5atemyhomework ;;; ;;; This file is part of GNU Guix. ;;; @@ -601,16 +602,6 @@ OS." (file-append (operating-system-kernel os) "/" (system-linux-image-file-name)))) -(define (package-for-kernel target-kernel module-package) - "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if -possible (that is if there's a LINUX keyword argument in the build system)= ." - (package - (inherit module-package) - (arguments - (substitute-keyword-arguments (package-arguments module-package) - ((#:linux kernel #f) - target-kernel))))) - (define %default-modprobe-blacklist ;; List of kernel modules to blacklist by default. '("usbmouse" ;races with bcm5974, see @@ -628,23 +619,12 @@ value of the SYSTEM-SERVICE-TYPE service." (let* ((locale (operating-system-locale-directory os)) (kernel (operating-system-kernel os)) (hurd (operating-system-hurd os)) - (modules (operating-system-kernel-loadable-modules os)) - (kernel (if hurd - kernel - (profile - (content (packages->manifest - (cons kernel - (map (lambda (module) - (if (package? module) - (package-for-kernel kern= el - modu= le) - module)) - modules)))) - (hooks (list linux-module-database))))) (initrd (and (not hurd) (operating-system-initrd-file os))) (params (operating-system-boot-parameters-file os))) - `(("kernel" ,kernel) - ,@(if hurd `(("hurd" ,hurd)) '()) + `(,@(if hurd + `(("hurd" ,hurd) + ("kernel" ,kernel)) + '()) ("parameters" ,params) ,@(if initrd `(("initrd" ,initrd)) '()) ("locale" ,locale)))) ;used by libc @@ -664,6 +644,10 @@ bookkeeping." (host-name (host-name-service (operating-system-host-name os))) (entries (operating-system-directory-base-entries os))) (cons* (service system-service-type entries) + (service linux-builder-service-type + (linux-builder-configuration + (kernel (operating-system-kernel os)) + (modules (operating-system-kernel-loadable-modules = os)))) %boot-service ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that diff --git a/gnu/tests/linux-modules.scm b/gnu/tests/linux-modules.scm index 953b132ef7..30d8eae03b 100644 --- a/gnu/tests/linux-modules.scm +++ b/gnu/tests/linux-modules.scm @@ -2,6 +2,7 @@ ;;; Copyright =C2=A9 2019 Jakob L. Kreuze ;;; Copyright =C2=A9 2020 Danny Milosavljevic ;;; Copyright =C2=A9 2020 Brice Waegeneire +;;; Copyright =C2=A9 2021 raid5atemyhomework ;;; ;;; This file is part of GNU Guix. ;;; @@ -34,7 +35,10 @@ #:use-module (guix utils) #:export (%test-loadable-kernel-modules-0 %test-loadable-kernel-modules-1 - %test-loadable-kernel-modules-2)) + %test-loadable-kernel-modules-2 + %test-loadable-kernel-modules-service-0 + %test-loadable-kernel-modules-service-1 + %test-loadable-kernel-modules-service-2)) ;;; Commentary: ;;; @@ -66,17 +70,11 @@ that MODULES are actually loaded." (member module modules string=3D?)) '#$modules)))))) -(define* (run-loadable-kernel-modules-test module-packages module-names) - "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAME= S -are loaded in memory." +(define* (run-loadable-kernel-modules-test-base base-os module-names) + "Run a test of BASE-OS, verifying that MODULE-NAMES are loaded in memory= ." (define os (marionette-operating-system - (operating-system - (inherit (simple-operating-system)) - (services (cons (service kernel-module-loader-service-type module-na= mes) - (operating-system-user-services - (simple-operating-system)))) - (kernel-loadable-modules module-packages)) + base-os #:imported-modules '((guix combinators)))) (define vm (virtual-machine os)) (define (test script) @@ -98,6 +96,36 @@ are loaded in memory." (gexp->derivation "loadable-kernel-modules" (test (modules-loaded?-program os module-names)))) +(define* (run-loadable-kernel-modules-test module-packages module-names) + "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAME= S +are loaded in memory." + (run-loadable-kernel-modules-test-base + (operating-system + (inherit (simple-operating-system)) + (services (cons (service kernel-module-loader-service-type module-na= mes) + (operating-system-user-services + (simple-operating-system)))) + (kernel-loadable-modules module-packages)) + module-names)) + +(define* (run-loadable-kernel-modules-service-test module-packages module-= names) + "Run a test of an OS having MODULE-PACKAGES, which are loaded by creatin= g a +service that extends LINUXL-LOADABLE-MODULE-SERVICE-TYPE. Then verify that +MODULE-NAMES are loaded in memory." + (define module-installing-service-type + (service-type + (name 'module-installing-service) + (extensions (list (service-extension linux-loadable-module-service-t= ype + (const module-packages)))) + (default-value #f))) + (run-loadable-kernel-modules-test-base + (operating-system + (inherit (simple-operating-system)) + (services (cons* (service module-installing-service-type) + (operating-system-user-services + (simple-operating-system))))) + module-names)) + (define %test-loadable-kernel-modules-0 (system-test (name "loadable-kernel-modules-0") @@ -129,3 +157,35 @@ with two extra modules.") (package-arguments ddcci-driver-linux)))))) '("acpi_call" "ddcci"))))) + +(define %test-loadable-kernel-modules-service-0 + (system-test + (name "loadable-kernel-modules-service-0") + (description "Tests loadable kernel modules extensible service with no +extra modules.") + (value (run-loadable-kernel-modules-service-test '() '())))) + +(define %test-loadable-kernel-modules-service-1 + (system-test + (name "loadable-kernel-modules-service-1") + (description "Tests loadable kernel modules extensible service with one +extra module.") + (value (run-loadable-kernel-modules-service-test + (list ddcci-driver-linux) + '("ddcci"))))) + +(define %test-loadable-kernel-modules-service-2 + (system-test + (name "loadable-kernel-modules-service-2") + (description "Tests loadable kernel modules extensible service with two +extra modules.") + (value (run-loadable-kernel-modules-service-test + (list acpi-call-linux-module + (package + (inherit ddcci-driver-linux) + (arguments + `(#:linux #f + ,@(strip-keyword-arguments '(#:linux) + (package-arguments + ddcci-driver-linux)))))) + '("acpi_call" "ddcci"))))) -- 2.31.0