guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading modules built using linux-module-build-system


From: Danny Milosavljevic
Subject: Re: Loading modules built using linux-module-build-system
Date: Mon, 21 Oct 2019 23:39:25 +0200

A patch to guix master which

* Puts the kernel modules (including any other packages that have "lib/modules"
inside their derivation) into /run/booted-system/profile/lib/modules
* Ensures that depmod is invoked on that
* Makes the modprobe wrapper use it

is provided below.

The case when there's only one package in the system profile (the package is the
kernel) could still be optimized:
Then, depmod doesn't need to run (it already ran when building the kernel in the
first place).

Probably, the profile hook will fail in some cases because modules.dep already
exists in the source.  The patch still needs to be adapted for that.

Also, tests need to be added (system test in vm).  Help wanted :)

(Right now I didn't test it because "guix system reconfigure" fails when
building qemu-4.1.0 three times in a row (for now), wasting many hours)

Also, long term, it might make sense to use something else instead of
profile-service-type (something like a new linux-module-service-type).

diff --git a/gnu/services.scm b/gnu/services.scm
index 6ee05d4580..d2977c2012 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -491,7 +491,11 @@ ACTIVATION-SCRIPT-TYPE."
     (program-file "modprobe"
                   #~(begin
                       (setenv "LINUX_MODULE_DIRECTORY"
-                              "/run/booted-system/kernel/lib/modules")
+                              (if (file-exists? 
"/run/booted-system/profile/lib/modules")
+                                  "/run/booted-system/profile/lib/modules"
+                                  ;; Provides compatibility with previous
+                                  ;; Guix generations.
+                                  "/run/booted-system/kernel/lib/modules"))
                       (apply execl #$modprobe
                              (cons #$modprobe (cdr (command-line))))))))
 
diff --git a/gnu/system.scm b/gnu/system.scm
index a353b1a5c8..2dfbb9e73f 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -887,9 +887,11 @@ we're running in the final root."
 (define* (operating-system-profile os)
   "Return a derivation that builds the system profile of OS."
   (mlet* %store-monad
-      ((services -> (operating-system-services os))
-       (profile (fold-services services
-                               #:target-type profile-service-type)))
+      ((kernel -> (operating-system-kernel os))
+       (services -> (operating-system-services os))
+       (profile (cons kernel (fold-services services
+                                            #:target-type
+                                            profile-service-type))))
     (match profile
       (("profile" profile)
        (return profile)))))
diff --git a/guix/profiles.scm b/guix/profiles.scm
index cd3b21e390..13b5bf1a85 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2017 Huang Ying <address@hidden>
 ;;; Copyright © 2017 Maxim Cournoyer <address@hidden>
 ;;; Copyright © 2019 Kyle Meyer <address@hidden>
+;;; Copyright © 2019 Danny Milosavljevic <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1125,6 +1126,43 @@ for both major versions of GTK+."
                               (hook . gtk-im-modules)))
           (return #f)))))
 
+(define (linux-module-database manifest)
+  (mlet %store-monad
+    ((kmod (manifest-lookup-package manifest "kmod")))
+    (define build
+      (with-imported-modules '((guix build utils)
+                               (guix build union))
+       #~(begin
+          (use-modules (srfi srfi-26)
+                       (guix build utils)
+                       (guix build union)
+                       (ice-9 match))
+          (let ((destdir (string-append #$output "/lib/modules"))
+                (dirs (filter file-exists?
+                              (map (cut string-append <>
+                                        "/lib/modules")
+                                   '#$(manifest-inputs manifest))))
+                (System.maps (filter file-exists?
+                              (map (cut string-append <> "/System.map")
+                                   '#$(manifest-inputs manifest))))
+                (Module.symvers (filter file-exists?
+                              (map (cut string-append <> "/Module.symvers")
+                                   '#$(manifest-inputs manifest)))))
+              (mkdir-p (string-append #$output "/lib"))
+              (union-build destdir dirs #:create-all-directories? #t)
+              (exit (zero? (system* (string-append #$kmod "/bin/depmod")
+                    "-e" ; Report symbols that aren't supplied
+                    "-w" ; Warn on duplicates
+                    "-b" destdir
+                    "-F" (match System.maps ((x) x))
+                    "-E" (match Module.symvers ((x) x)))))))))
+    (gexp->derivation "linux-module-database" build
+                      #:local-build? #t
+                      #:substitutable? #f
+                      #:properties
+                      `((type . profile-hook)
+                        (hook . linux-module-database)))))
+
 (define (xdg-desktop-database manifest)
   "Return a derivation that builds the @file{mimeinfo.cache} database from
 desktop files.  It's used to query what applications can handle a given
@@ -1425,7 +1463,8 @@ MANIFEST."
         gtk-im-modules
         texlive-configuration
         xdg-desktop-database
-        xdg-mime-database))
+        xdg-mime-database
+        linux-module-database))
 
 (define* (profile-derivation manifest
                              #:key

Attachment: pgpPCnhGYLQbt.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]