From patchwork Wed Jan 6 15:54:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: raid5atemyhomework X-Patchwork-Id: 26244 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 328F827BC0F; Wed, 6 Jan 2021 15:55:16 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2B54627BC0E for ; Wed, 6 Jan 2021 15:55:15 +0000 (GMT) Received: from localhost ([::1]:40934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxB9W-0001OS-CU for patchwork@mira.cbaines.net; Wed, 06 Jan 2021 10:55:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxB9L-0001Nx-0H for guix-patches@gnu.org; Wed, 06 Jan 2021 10:55:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:33753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kxB9J-0005oR-SI for guix-patches@gnu.org; Wed, 06 Jan 2021 10:55:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kxB9J-00021U-Rb for guix-patches@gnu.org; Wed, 06 Jan 2021 10:55:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45692] [PATCH 1/4] 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: Wed, 06 Jan 2021 15:55:01 +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.16099484947757 (code B ref 45692); Wed, 06 Jan 2021 15:55:01 +0000 Received: (at 45692) by debbugs.gnu.org; 6 Jan 2021 15:54:54 +0000 Received: from localhost ([127.0.0.1]:45299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxB97-00020x-L4 for submit@debbugs.gnu.org; Wed, 06 Jan 2021 10:54:54 -0500 Received: from mail-40132.protonmail.ch ([185.70.40.132]:19967) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxB92-00020b-GN for 45692@debbugs.gnu.org; Wed, 06 Jan 2021 10:54:48 -0500 Date: Wed, 06 Jan 2021 15:54:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1609948477; bh=hGPrUa6tM+1uugZYWcqsoLzUVtMpEchptuPfK1FnEJg=; h=Date:To:From:Reply-To:Subject:From; b=t54NBqbXP5kB/Kjrstc3ARP9sUJWzISaby8HMNpvRGeebjx5kt26uvbY1FjBIEmss KToZQh4So8J/A+bx4i5SzJ2v5SXjVoXSzbVgzjLOq/rhrgwVyHECZKSB+GYmkWOue1 CIBIy9EbQ9gN1MxN6dqfI/H/e60cadqGjsHFmizc= Message-ID: <2yOs7mxigs8_Vx_yi858pxAkoyXmU8IidizK5grcmX4M92O5QK-_Ywo9nrHMHvzLGj4U7B9ysl26eNbiPmzmeOQsuFvp5VjouVptRfwxKng=@protonmail.com> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: raid5atemyhomework , raid5atemyhomework via Guix-patches X-Patchwork-Original-From: raid5atemyhomework via Guix-patches via From: raid5atemyhomework X-getmail-retrieved-from-mailbox: Patches From 4beb73c62995cf236b402dad8e1c36016027c781 Mon Sep 17 00:00:00 2001 From: raid5atemyhomework Date: Tue, 5 Jan 2021 22:27:56 +0800 Subject: [PATCH 1/4] gnu: Allow services to install kernel-loadable modules. * gnu/system.scm (operating-system-directory-base-entries): Remove code to handle generation of "kernel" and "hurd". (operating-system-default-essential-services): Instantiate kernel-loadable-module-service. (hurd-default-essential-services): Instantiate kernel-loadable-module-service. (package-for-kernel): Move ... * gnu/services.scm: ... to here. (kernel-loadable-module-service-type): New variable. (kernel-loadable-module-service): New procedure. * 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 kernel-loadable-module-service-type. --- doc/guix.texi | 6 +++ gnu/services.scm | 70 ++++++++++++++++++++++++++++++++ gnu/system.scm | 37 +++++------------ gnu/tests/linux-modules.scm | 81 ++++++++++++++++++++++++++++++++----- 4 files changed, 157 insertions(+), 37 deletions(-) -- 2.29.2 diff --git a/doc/guix.texi b/doc/guix.texi index 0f6e95a65a..78770151e3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -32409,6 +32409,12 @@ configuration when you use @command{guix system reconfigure}, @command{guix system init}, or @command{guix deploy}. @end defvr +@defvr {Scheme Variable} kernel-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. +@end defvr + @node Shepherd Services @subsection Shepherd Services diff --git a/gnu/services.scm b/gnu/services.scm index 13259dfaee..d7332a46b2 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2016 Chris Marusich ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright © 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) @@ -75,6 +78,7 @@ service-back-edges instantiate-missing-services fold-services + kernel-loadable-module-service service-error? missing-value-service-error? @@ -106,6 +110,7 @@ profile-service-type firmware-service-type gc-root-service-type + kernel-loadable-module-service-type %boot-service %activation-service @@ -864,6 +869,71 @@ as Wifi cards."))) will not be reclaimed by the garbage collector.") (default-value '()))) +;; Configuration for the kernel builder. +(define-record-type* kernel-builder-configuration + make-kernel-builder-configuration + kernel-builder-configuration? + this-kernel-builder-configuration + + (kernel kernel-builder-configuration-kernel (default #f)) + (hurd kernel-builder-configuration-hurd (default #f)) + (modules kernel-builder-configuration-modules (default '()))) + +(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 (kernel-builder-configuration->system-entry config) + "Return the kernel and hurd entries of the 'system' directory." + (mbegin %store-monad + (let* ((kernel (kernel-builder-configuration-kernel config)) + (hurd (kernel-builder-configuration-hurd config)) + (modules (kernel-builder-configuration-modules config)) + (kernel (if hurd + kernel + (profile + (content (packages->manifest + (cons kernel + (map (lambda (module) + (if (package? module) + (package-for-kernel kernel module) + module)) + modules)))) + (hooks (list linux-module-database)))))) + (return `(("kernel" ,kernel) + ,@(if hurd `(("hurd" ,hurd)) '())))))) + +(define (kernel-builder-configuration-add-modules config modules) + "Constructs a kernel builder configuration that has its modules extended." + (kernel-builder-configuration + (inherit config) + (modules (append (kernel-builder-configuration-modules config) modules)))) + +(define kernel-loadable-module-service-type + (service-type (name 'kernel-loadable-modules) + (extensions + (list (service-extension system-service-type + kernel-builder-configuration->system-entry))) + (compose concatenate) + (extend kernel-builder-configuration-add-modules) + (description + "Register packages containing kernel-loadable modules and adds them +to the system."))) + +(define (kernel-loadable-module-service kernel hurd modules) + "Constructs the service that sets up kernel loadable modules." + (service kernel-loadable-module-service-type + (kernel-builder-configuration + (kernel kernel) + (hurd hurd) + (modules modules)))) + ;;; ;;; Service folding. diff --git a/gnu/system.scm b/gnu/system.scm index c284a18379..5c530f176e 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -12,6 +12,7 @@ ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2020 Efraim Flashner +;;; Copyright © 2021 raid5atemyhomework ;;; ;;; This file is part of GNU Guix. ;;; @@ -600,16 +601,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 @@ -625,26 +616,10 @@ possible (that is if there's a LINUX keyword argument in the build system)." "Return the basic entries of the 'system' directory of OS for use as the 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 kernel - module) - 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)) '()) - ("parameters" ,params) + `(("parameters" ,params) ,@(if initrd `(("initrd" ,initrd)) '()) ("locale" ,locale)))) ;used by libc @@ -663,6 +638,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) + (kernel-loadable-module-service + (operating-system-kernel os) + (operating-system-hurd os) + (operating-system-kernel-loadable-modules os)) %boot-service ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that @@ -699,6 +678,10 @@ bookkeeping." (define (hurd-default-essential-services os) (let ((entries (operating-system-directory-base-entries os))) (list (service system-service-type entries) + (kernel-loadable-module-service + (operating-system-kernel os) + (operating-system-hurd os) + (operating-system-kernel-loadable-modules os)) %boot-service %hurd-startup-service %activation-service diff --git a/gnu/tests/linux-modules.scm b/gnu/tests/linux-modules.scm index 953b132ef7..9739e4124d 100644 --- a/gnu/tests/linux-modules.scm +++ b/gnu/tests/linux-modules.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2019 Jakob L. Kreuze ;;; Copyright © 2020 Danny Milosavljevic ;;; Copyright © 2020 Brice Waegeneire +;;; Copyright © 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=?)) '#$modules)))))) -(define* (run-loadable-kernel-modules-test module-packages module-names) - "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES -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-names) - (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,37 @@ 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-NAMES +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-names) + (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 creating a +service that extends KERNEL-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 kernel-loadable-module-service-type + (const module-packages)))) + (default-value #f))) + (run-loadable-kernel-modules-test-base + (operating-system + (inherit (simple-operating-system)) + (services (cons* (service kernel-module-loader-service-type module-names) + (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 +158,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")))))