Subject: bug#40274: closed (Re: [bug#40274] [PATCH v7 2/2] gnu: Add kernel-module-loader-service.)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 05 Apr 2020 11:11:02 +0000

Your bug report

#40274: [PATCH] gnu: Add kernel-module-loader-service.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
40274: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=40274
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug#40274] [PATCH v7 2/2] gnu: Add kernel-module-loader-service.
From: Danny Milosavljevic <[email-masked]>
To: Brice Waegeneire <[email-masked]>
Cc: [email-masked]
Date: Sun, 5 Apr 2020 13:10:16 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi Brice,

I've pushed a variant of this to guix master as
commit 044d1478c9a63a64547c9cc320008f8d8fbf6791 with the following changes:

* Massively over-engineered the tests
* Made the shepherd conditional more readable

Thanks!

Subject: [PATCH] gnu: Add kernel-module-loader-service.
From: Brice Waegeneire <[email-masked]>
To: [email-masked]
Date: Sat, 28 Mar 2020 14:59:08 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

* doc/guix.texi (Linux Services): Add a new subsection and document the
new service and its configuration.
* gnu/services/linux.scm (kernel-module-loader-service): New procedure.
(kernel-module-loader-service-type, kernel-module-loader-configuration):
New types.
---

This patch is related to the following thread:
https://lists.gnu.org/archive/html/guix-devel/2020-03/msg00381.html

 doc/guix.texi          | 48 ++++++++++++++++++++++++++++++++++
 gnu/services/linux.scm | 58 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 77a4b8ed71..a297ec249f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -75,6 +75,7 @@ Copyright @copyright{} 2020 Wiktor Żelazny@*
 Copyright @copyright{} 2020 Damien Cassou@*
 Copyright @copyright{} 2020 Jakub Kądziołka@*
 Copyright @copyright{} 2020 Jack Hill@*
+Copyright @copyright{} 2020 Brice Waegeneire@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -25382,6 +25383,53 @@ notifications.
 @end table
 @end deftp
 
+@cindex modprobe
+@cindex kernel module loader
+@subsubsection Kernel Module Loader Service
+
+The @code{kernel-module-loader-service} provides a service to load
+kernel modules at boot.  This is especially usefull for modules that
+don't autoload and need to be manually loaded, like it's the case with
+@code{ddcci} for example.
+
+@deffn {Scheme Procedure} kernel-module-loader-service @var{modules}
+Return a service that run @command{modprobe} with arguments
+@var{modules} at boot.  For example loading the drivers provided by
+@code{ddci-driver-linux} can be done as follow:
+
+@lisp
+(use-modules (gnu))
+(use-package-modules linux)
+(use-service-modules linux)
+(operating-system
+  ...
+  (services (cons* (kernel-module-loader-service
+                     '("ddcci""ddcci_backlight"))
+                   %base-services))
+  (kernel-loadable-modules (list ddcci-driver-linux)))
+@end lisp
+@end defvr
+
+@deffn {Scheme Variable} kernel-module-loader-service-type
+The service type for loading kernel modules, that can't autoload, at
+boot, @command{modprobe}, on.  Its value must be a
+@code{kernel-module-loader-configuration} object, described below.
+
+@deftp {Data Type} kernel-module-loader-configuration
+The data type representing the configuration of @command{sysctl}.
+
+@deftp {Data Type} kernel-module-loader-configuration
+This is the configuration record for the
+@code{kernel-module-loader-service-type}.
+
+@table @asis
+@item @code{modprobe} (default: @code{(file-append kmod "/bin/modprobe"})
+The @command{modprobe} executable to use.
+
+@item @code{modules} (default: @code{'()})
+A list specifying the modules to load.
+@end table
+@end deftp
 
 @node Miscellaneous Services
 @subsection Miscellaneous Services
diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm
index caa0326c31..99ab4a3329 100644
--- a/gnu/services/linux.scm
+++ b/gnu/services/linux.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2020 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2020 Brice Waegeneire <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -37,7 +38,14 @@
             earlyoom-configuration-ignore-positive-oom-score-adj?
             earlyoom-configuration-show-debug-messages?
             earlyoom-configuration-send-notification-command
-            earlyoom-service-type))
+            earlyoom-service-type
+
+            kernel-module-loader-configuration
+            kernel-module-loader-configuration?
+            kernel-module-loader-configuration-modprobe
+            kernel-module-loader-configuration-modules
+            kernel-module-loader-service-type
+            kernel-module-loader-service))
 
 
 ;;;
@@ -123,3 +131,51 @@ representation."
     (list (service-extension shepherd-root-service-type
                              (compose list earlyoom-shepherd-service))))
    (description "Run @command{earlyoom}, the Early OOM daemon.")))
+
+;;;
+;;; Kernel module loader.
+;;;
+
+(define-record-type* <kernel-module-loader-configuration>
+  kernel-module-loader-configuration make-kernel-module-loader-configuration
+  kernel-module-loader-configuration?
+  (modprobe kernel-module-loader-configuration-modprobe ; path of the 'modprobe' command
+            (default (file-append kmod "/bin/modprobe")))
+  (modules kernel-module-loader-configuration-modules ; list of strings
+           (default '())))
+
+(define kernel-module-loader-shepherd-service
+  (match-lambda
+    (($ <kernel-module-loader-configuration> modprobe modules)
+     (list
+      (shepherd-service
+       (documentation "Load kernel modules.")
+       (provision '(kernel-module-loader))
+       (respawn? #f)
+       (one-shot? #t)
+       (start
+        #~(lambda _
+            (zero? (system* #$modprobe #$@modules)))))))))
+
+(define kernel-module-loader-service-type
+  (service-type
+   (name 'kernel-module-loader)
+   (description "Load kernel modules.")
+   (extensions
+    (list
+     (service-extension shepherd-root-service-type
+                        kernel-module-loader-shepherd-service)))
+   (compose concatenate)
+   (extend (lambda (config modules)
+             (kernel-module-loader-configuration
+              (inherit config)
+              (modules (append
+                        (kernel-module-loader-configuration-modules config)
+                        modules)))))
+   (default-value (kernel-module-loader-configuration))))
+
+(define* (kernel-module-loader-service modules)
+  "Return a service that loads kernel MODULES."
+  (service kernel-module-loader-service-type
+           (kernel-module-loader-configuration
+            (modules modules))))
-- 
2.25.1