Subject: [bug#42193] [WIP 5/6] WIP services: Add kernel-arguments-service-type.

From: Brice Waegeneire <[email-masked]>
Date: Sat, 4 Jul 2020 20:54:30 +0200

---
 gnu/services.scm | 14 ++++++++++++++
 gnu/system.scm   | 39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/gnu/services.scm b/gnu/services.scm
index 7df9bf9d46..7cf71ae97a 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -538,6 +538,20 @@ possible (that is if there's a LINUX keyword argument in the build system)."
                              (kernel kernel)   ;the kernel package to use
                              (packages (append packages additional-packages))))))))
 
+
+;;;
+;;; Kernel arguments.
+;;;
+
+;; (define kernel-arguments-service-type
+;;   (service-type (name 'kernel-arguments)
+;;                 (description "Set the kernel arguments.")
+;;                 (extensions
+;;                  (list (service-extension system-service-type
+;;                                           kernel-arguments->profile-entry)))
+;;                 (compose concatenate)
+;;                 (extend append)))
+
 
 ;;;
 ;;; Cleanup.
diff --git a/gnu/system.scm b/gnu/system.scm
index ba9eeb66b8..805aa2ab01 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -56,6 +56,7 @@
   #:use-module (gnu packages compression)
   #:use-module (gnu packages firmware)
   #:use-module (gnu services)
+  #:use-module (gnu services linux)
   #:use-module (gnu services shepherd)
   #:use-module (gnu services base)
   #:use-module (gnu services linux)
@@ -258,11 +259,37 @@
   (sudoers-file operating-system-sudoers-file     ; file-like
                 (default %sudoers-specification)))
 
+(define (operating-system-modules-kernel-arguments os)
+  "Return the kernel arguments for builtin modules specified in
+<kernel-module-configuration-service-type> from OS."
+  (let* ((kernel-module-configuration-service
+          (find (lambda (service)
+                  (eq? (service-kind service)
+                       kernel-module-configuration-service-type))
+                (operating-system-user-services os)))
+         (modules (if kernel-module-configuration-service
+                      (service-value kernel-module-configuration-service)
+                      '())))
+    (display kernel-module-configuration-service)
+    (display (concatenate
+     (filter-map (lambda (module)
+                   (if (kernel-module-is-builtin? module)
+                       (kernel-module->kernel-arguments module)
+                       #f))
+                 modules)))
+    (concatenate
+     (filter-map (lambda (module)
+                   (if (kernel-module-is-builtin? module)
+                       (kernel-module->kernel-arguments module)
+                       #f))
+                 modules))))
+
 (define (operating-system-kernel-arguments os root-device)
   "Return all the kernel arguments, including the ones not specified
 directly by the user."
   (append (bootable-kernel-arguments os root-device)
-          (operating-system-user-kernel-arguments os)))
+          (operating-system-user-kernel-arguments os)
+          (operating-system-modules-kernel-arguments os)))
 
 
 ;;;
@@ -512,6 +539,7 @@ OS."
       (file-append (operating-system-kernel os)
                       "/" (system-linux-image-file-name))))
 
+;; TODO Migrate to KMCS
 (define %default-modprobe-blacklist
   ;; List of kernel modules to blacklist by default.
   '("usbmouse" ;races with bcm5974, see <https://bugs.gnu.org/35574>
@@ -569,6 +597,11 @@ bookkeeping."
                     (kernel-profile-configuration
                      (kernel (operating-system-kernel os))
                      (packages (operating-system-kernel-loadable-modules os))))
+           ;; (service kernel-arguments-service-type
+           ;;          (kernel-arguments-configuration
+           ;;           (root (operating-system-root-file-system os))
+           ;;           (bootloader (operating-system-bootloader os))
+           ;;           (parameters "TODO")))
            %boot-service
 
            ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that
@@ -1232,7 +1265,9 @@ such as '--root' and '--load' to <boot-parameters>."
      (kernel-arguments
       (if system-kernel-arguments?
           (operating-system-kernel-arguments os root-device)
-          (operating-system-user-kernel-arguments os)))
+          (append
+           (operating-system-user-kernel-arguments os)
+           (operating-system-modules-kernel-arguments os))))
      (initrd initrd)
      (multiboot-modules multiboot-modules)
      (bootloader-name bootloader-name)
-- 
2.26.2