unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#40274] [PATCH] gnu: Add kernel-module-loader-service.
@ 2020-03-28 13:59 Brice Waegeneire
  2020-03-28 20:51 ` Mathieu Othacehe
                   ` (7 more replies)
  0 siblings, 8 replies; 44+ messages in thread
From: Brice Waegeneire @ 2020-03-28 13:59 UTC (permalink / raw)
  To: 40274

* 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 <maxim.cournoyer@gmail.com>
+;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
 ;;;
 ;;; 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))
 
 \f
 ;;;
@@ -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

^ permalink raw reply related	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2020-04-05 12:39 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 13:59 [bug#40274] [PATCH] gnu: Add kernel-module-loader-service Brice Waegeneire
2020-03-28 20:51 ` Mathieu Othacehe
2020-03-31 17:22   ` Brice Waegeneire
2020-03-31 17:19 ` [bug#40274] [PATCH v2] " Brice Waegeneire
2020-03-31 20:00 ` [bug#40274] [PATCH v3] " Brice Waegeneire
2020-03-31 20:10 ` [bug#40274] [PATCH] " Nicolò Balzarotti
2020-03-31 20:25   ` Brice Waegeneire
2020-03-31 20:23 ` [bug#40274] [PATCH v4] " Brice Waegeneire
2020-04-01 13:30   ` Mathieu Othacehe
2020-04-01 14:38     ` Brice Waegeneire
2020-04-01 19:34   ` pelzflorian (Florian Pelz)
2020-04-01 19:43     ` pelzflorian (Florian Pelz)
2020-04-01 19:48       ` pelzflorian (Florian Pelz)
2020-04-02 12:40     ` Brice Waegeneire
2020-04-03 13:03       ` pelzflorian (Florian Pelz)
2020-04-02 12:37 ` [bug#40274] [PATCH v5] " Brice Waegeneire
2020-04-02 13:56   ` Danny Milosavljevic
2020-04-02 17:13     ` Brice Waegeneire
2020-04-03 10:20       ` Danny Milosavljevic
2020-04-03 12:58         ` pelzflorian (Florian Pelz)
2020-04-04 10:51         ` Danny Milosavljevic
2020-04-04 17:58         ` Brice Waegeneire
2020-04-04 18:31           ` Danny Milosavljevic
2020-04-05  7:19             ` Brice Waegeneire
2020-04-02 14:22   ` Mathieu Othacehe
2020-04-04 15:17 ` [bug#40274] [PATCH v6 0/2] " Brice Waegeneire
2020-04-04 15:17   ` [bug#40274] [PATCH v6 1/2] services: Allow modprobe to use "/etc/modprobe.d" Brice Waegeneire
2020-04-04 15:17   ` [bug#40274] [PATCH v6 2/2] gnu: Add kernel-module-loader-service Brice Waegeneire
2020-04-04 15:53     ` Mathieu Othacehe
2020-04-04 16:09     ` pelzflorian (Florian Pelz)
2020-04-04 16:49       ` Brice Waegeneire
2020-04-04 17:46         ` pelzflorian (Florian Pelz)
2020-04-04 21:10     ` Danny Milosavljevic
2020-04-04 21:11       ` Danny Milosavljevic
2020-04-04 23:06         ` pelzflorian (Florian Pelz)
2020-04-05  7:06         ` Brice Waegeneire
2020-04-04 21:16     ` Danny Milosavljevic
2020-04-05  5:28 ` [bug#40274] [PATCH v7 0/2] " Brice Waegeneire
2020-04-05  5:28   ` [bug#40274] [PATCH v7 1/2] services: Allow modprobe to use "/etc/modprobe.d" Brice Waegeneire
2020-04-05 11:11     ` Danny Milosavljevic
2020-04-05 12:38       ` Brice Waegeneire
2020-04-05  5:28   ` [bug#40274] [PATCH v7 2/2] gnu: Add kernel-module-loader-service Brice Waegeneire
2020-04-05 10:06     ` pelzflorian (Florian Pelz)
2020-04-05 11:10     ` bug#40274: " Danny Milosavljevic

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).