diff mbox series

[bug#42193,WIP,2/6] services: Add 'kernel-profile-service-type'.

Message ID 20200704185431.13739-3-brice@waegenei.re
State New
Headers show
Series Add kernel-module-configuration service | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Brice Waegeneire July 4, 2020, 6:54 p.m. UTC
* gnu/system.scm (operating-system-default-essential-services): Use
'kernel-profile-service-type'.
(operating-system-default-essential-services): Remove kernel profile.
(package-for-kernel): Move it to …
* gnu/services.scm (package-for-kernel): … here.
(kernel-profile-configuration,
kernel-profile-configuration->profile-entry,
kernel-profile-service-type): New variables.
* gnu/tests/linux-modules.scm (run-loadable-kernel-modules-test): Test
'kernel-profile-service-type'.
---
 gnu/services.scm            | 66 ++++++++++++++++++++++++++++++++++++-
 gnu/system.scm              | 14 +++-----
 gnu/tests/linux-modules.scm | 10 +++---
 3 files changed, 75 insertions(+), 15 deletions(-)

Comments

pelzflorian (Florian Pelz) July 8, 2020, 11:29 a.m. UTC | #1
Thank you for your work!

After I apply this kernel profile patch, I get an error:

florian@florianmacbook ~/git/guix [env]$ ./pre-inst-env guix system disk-image --file-system-type=iso9660        gnu/system/install.scm
substitute: Liste der Substitute von „https://ci.guix.gnu.org“ wird aktualisiert … 100.0%
The following derivations will be built:
   /gnu/store/l51h17zylvjmapvcpdmmqmvrylv8b2cb-iso9660-image.drv
   /gnu/store/mhdkqnh4iri5rk1ayqd3xlw04q86zj29-grub.cfg.drv
   /gnu/store/xvgn60irpzzdwvk30lqpsj2hh81h8jyh-system.drv
   /gnu/store/6y2r0ab5jcflbajd6843v9g1j0v9xrzj-gc-roots.drv
   /gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv
building /gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv...
|builder for `/gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv' failed with exit code 1
build of /gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv failed
View build log at '/var/log/guix/drvs/15/6m13243bcn2429swq8brp2qmfifi3b-system.drv.bz2'.
cannot build derivation `/gnu/store/6y2r0ab5jcflbajd6843v9g1j0v9xrzj-gc-roots.drv': 1 dependencies couldn't be built
cannot build derivation `/gnu/store/xvgn60irpzzdwvk30lqpsj2hh81h8jyh-system.drv': 1 dependencies couldn't be built
cannot build derivation `/gnu/store/l51h17zylvjmapvcpdmmqmvrylv8b2cb-iso9660-image.drv': 1 dependencies couldn't be built
guix system: error: build of `/gnu/store/l51h17zylvjmapvcpdmmqmvrylv8b2cb-iso9660-image.drv' failed
florian@florianmacbook ~/git/guix [env]$ bzcat /var/log/guix/drvs/15/6m13243bcn2429swq8brp2qmfifi3b-system.drv.bz2
Backtrace:
           1 (primitive-load "/gnu/store/59nx7bbflcqzavwsjj3wkq3lwfb?")
           0 (symlink "/gnu/store/86xgvarqwir47c16x6crx0jra5dgzr62-?" ?)

ERROR: In procedure symlink:
In procedure symlink: File exists


I have no idea where this comes from but I hope you can reproduce the error.

In general, I would be happy to use the kernel module configuration
service for replacing the uvesafb-service-type by something like

 (simple-service 'uvesafb-module
             kernel-module-configuration-service-type
             (list (kernel-module
                    (name "uvesafb")
                    (options
                     (list #~(string-append "v86d=" #$v86d "/sbin/v86d")
                           "mode_option=1024x768\n"))))))))

Even better would be if it were possible to detect the resolution to
use for uvesafb at runtime before the module is loaded.  Is it
possible to execute as root at runtime before modprobe a script like
testvbe.scm attached to the first message from
<https://issues.guix.gnu.org/40538#0> to compute the mode_option to
use?

Regards,
Florian
Brice Waegeneire July 8, 2020, 4:22 p.m. UTC | #2
On 2020-07-08 11:29, pelzflorian (Florian Pelz) wrote:
> Thank you for your work!

Note that it's not finished yet.

> After I apply this kernel profile patch, I get an error:
> 
> florian@florianmacbook ~/git/guix [env]$ ./pre-inst-env guix system
> disk-image --file-system-type=iso9660        gnu/system/install.scm
> substitute: Liste der Substitute von „https://ci.guix.gnu.org“ wird
> aktualisiert … 100.0%
> The following derivations will be built:
>    /gnu/store/l51h17zylvjmapvcpdmmqmvrylv8b2cb-iso9660-image.drv
>    /gnu/store/mhdkqnh4iri5rk1ayqd3xlw04q86zj29-grub.cfg.drv
>    /gnu/store/xvgn60irpzzdwvk30lqpsj2hh81h8jyh-system.drv
>    /gnu/store/6y2r0ab5jcflbajd6843v9g1j0v9xrzj-gc-roots.drv
>    /gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv
> building /gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv...
> |builder for `/gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv'
> failed with exit code 1
> build of /gnu/store/156m13243bcn2429swq8brp2qmfifi3b-system.drv failed
> View build log at
> '/var/log/guix/drvs/15/6m13243bcn2429swq8brp2qmfifi3b-system.drv.bz2'.
> cannot build derivation
> `/gnu/store/6y2r0ab5jcflbajd6843v9g1j0v9xrzj-gc-roots.drv': 1
> dependencies couldn't be built
> cannot build derivation
> `/gnu/store/xvgn60irpzzdwvk30lqpsj2hh81h8jyh-system.drv': 1
> dependencies couldn't be built
> cannot build derivation
> `/gnu/store/l51h17zylvjmapvcpdmmqmvrylv8b2cb-iso9660-image.drv': 1
> dependencies couldn't be built
> guix system: error: build of
> `/gnu/store/l51h17zylvjmapvcpdmmqmvrylv8b2cb-iso9660-image.drv' failed
> florian@florianmacbook ~/git/guix [env]$ bzcat
> /var/log/guix/drvs/15/6m13243bcn2429swq8brp2qmfifi3b-system.drv.bz2
> Backtrace:
>            1 (primitive-load "/gnu/store/59nx7bbflcqzavwsjj3wkq3lwfb?")
>            0 (symlink "/gnu/store/86xgvarqwir47c16x6crx0jra5dgzr62-?" 
> ?)
> 
> ERROR: In procedure symlink:
> In procedure symlink: File exists
> 
> 
> I have no idea where this comes from but I hope you can reproduce the 
> error.

Unfortunately I can't, it build successfully for me when applied on top 
of
6f3ede9ae2b2268181ebc0ca3764d865bd06bd63.  You probably just need to 
clean
your Guix repository and rebuild it from scratch

> In general, I would be happy to use the kernel module configuration
> service for replacing the uvesafb-service-type by something like
> 
>  (simple-service 'uvesafb-module
>              kernel-module-configuration-service-type
>              (list (kernel-module
>                     (name "uvesafb")
>                     (options
>                      (list #~(string-append "v86d=" #$v86d 
> "/sbin/v86d")
>                            "mode_option=1024x768\n"))))))))

I think it should work without gexp/ungexp and the "\n".

> Even better would be if it were possible to detect the resolution to
> use for uvesafb at runtime before the module is loaded.  Is it
> possible to execute as root at runtime before modprobe a script like
> testvbe.scm attached to the first message from
> <https://issues.guix.gnu.org/40538#0> to compute the mode_option to
> use?

AFAIU it's not possible because service extensions are generated at 
build time,
not run time so you can't extend KMCS with a value generated when your 
service
is executed. It is a limitation of the service extension paradigm.

A kind of dirty way to achieve what you want would be for KMCS' options 
field
to accept an arbitrary configuration path that will be symlinked to, 
like
“(options "/var/run/uvesafb/uvesafb.conf")”. That way from uvesafb 
service
you generate that modprobe configuration file at run time (before KMCS) 
and
so when KMCS run modprobe it's direcotry configuration contains a 
symlink
named "uvesafb.conf" which point to "/var/run/uvesafb/uvesafb.conf". But
it doesn't seems Guixy to me.

- Brice
pelzflorian (Florian Pelz) July 11, 2020, 5:30 p.m. UTC | #3
On Wed, Jul 08, 2020 at 04:22:06PM +0000, Brice Waegeneire wrote:
> > After I apply this kernel profile patch, I get an error:
> > 
> > florian@florianmacbook ~/git/guix [env]$ ./pre-inst-env guix system
> > disk-image --file-system-type=iso9660        gnu/system/install.scm
> > […]
> > failed with exit code 1
> > […]
> > In procedure symlink: File exists
> > 
> > 
> > I have no idea where this comes from but I hope you can reproduce the
> > error.
> 
> Unfortunately I can't, it build successfully for me when applied on top of
> 6f3ede9ae2b2268181ebc0ca3764d865bd06bd63.  You probably just need to clean
> your Guix repository and rebuild it from scratch

I still have the error after pulling current guix (commit f2dce740b2)
and applying your patch.

florian@florianmacbook ~/.config/guix/current/share/guile/site/3.0$ guix system disk-image --file-system-type=iso9660 gnu/system/install.scm
[…]
build of /gnu/store/v9jzdiykyz1rdb1an7jpsfhnnkvx21mq-system.drv failed
View build log at '/var/log/guix/drvs/v9/jzdiykyz1rdb1an7jpsfhnnkvx21mq-system.drv.bz2'.

Indeed /gnu/store/v9jzdiykyz1rdb1an7jpsfhnnkvx21mq-system.drv contains

Derive([("out","/gnu/store/xzavg5awkmbcx556f3a0h329w5ninhyk-system","","")],[("/gnu/store/28zlas3x4ry6q88fgq625ixh40igjws5-guile-3.0.2.drv",["out"]),("/gnu/store/32yj3cnz8rjipd6lw27d08rb272rcmbp-boot.drv",["out"]),("/gnu/store/6iwq8qmqpf9sy84jvbbsd6lwwb05rvlf-etc.drv",["out"]),("/gnu/store/8rfp2v0vz8w72621qsr0mr21zgr5f062-profile.drv",["out"]),("/gnu/store/92sqsa639hl3ixy6ryys38xha7mgkyb0-profile.drv",["out"]),("/gnu/store/ca0g4jfdqx4fhsp67jr2ra17sdwajczc-parameters.drv",["out"]),("/gnu/store/fi6hy331yp7pn03zhlxavdd4d9kv6l6i-raw-initrd.drv",["out"]),("/gnu/store/i3fx8c0k6yna92cf9h7r57amdjzii7l3-locale-multiple-versions.drv",["out"]),("/gnu/store/zcz3jhx84q3zmz37wddwlfk2w3rnn5fc-module-import-compiled.drv",["out"])],["/gnu/store/ah60schb9jlzx12jzi6v872q3j099afi-system-builder","/gnu/store/xv5ylv9hxvs1wraw375b5g9jwy57vs8p-module-import"],"x86_64-linux","/gnu/store/0m0vd873jp61lcm4xa3ljdgx381qa782-guile-3.0.2/bin/guile",["--no-auto-compile","-L","/gnu/store/xv5ylv9hxvs1wraw375b5g9jwy57vs8p-module-import","-C","/gnu/store/08da6i38fzn9g36gyq443k03f84nk8rk-module-import-compiled","/gnu/store/ah60schb9jlzx12jzi6v872q3j099afi-system-builder"],[("out","/gnu/store/xzavg5awkmbcx556f3a0h329w5ninhyk-system"),("preferLocalBuild","1")])

and /gnu/store/ah60schb9jlzx12jzi6v872q3j099afi-system-builder
contains (with indentation added by me):

(begin (use-modules (guix build utils))
       (mkdir ((@ (guile) getenv) "out"))
       (chdir ((@ (guile) getenv) "out"))
       (begin (stat "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile")
              (mkdir-p (dirname "kernel"))
              (symlink "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile" "kernel"))
       (begin (stat "/gnu/store/7wjapypmzz4n93rwrnrrqwalwg8hhh3h-parameters")
              (mkdir-p (dirname "parameters"))
              (symlink "/gnu/store/7wjapypmzz4n93rwrnrrqwalwg8hhh3h-parameters" "parameters"))
       (begin (stat "/gnu/store/j27l3k8zjg9gn9j04y90gsjrqsryjapw-raw-initrd/initrd.cpio.gz")
              (mkdir-p (dirname "initrd"))
              (symlink "/gnu/store/j27l3k8zjg9gn9j04y90gsjrqsryjapw-raw-initrd/initrd.cpio.gz" "initrd"))
       (begin (stat "/gnu/store/bhnyk7bpzlzna28njkx21dd3940m1m4a-locale-multiple-versions")
              (mkdir-p (dirname "locale"))
              (symlink "/gnu/store/bhnyk7bpzlzna28njkx21dd3940m1m4a-locale-multiple-versions" "locale"))
       (begin (stat "/gnu/store/24irabcnv3pn2mpx4cjrggmlvn30k053-profile")
              (mkdir-p (dirname "profile"))
              (symlink "/gnu/store/24irabcnv3pn2mpx4cjrggmlvn30k053-profile" "profile"))
       (begin (stat "/gnu/store/z9jm8d8rrrpq19y1pmahpp73ja5ydw6h-etc")
              (mkdir-p (dirname "etc"))
              (symlink "/gnu/store/z9jm8d8rrrpq19y1pmahpp73ja5ydw6h-etc" "etc"))
       (begin (stat "/gnu/store/w90vvv7mx8g17i6frd34yvmbfi0nhnl1-boot")
              (mkdir-p (dirname "boot"))
              (symlink "/gnu/store/w90vvv7mx8g17i6frd34yvmbfi0nhnl1-boot" "boot"))
       (begin (stat "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile")
              (mkdir-p (dirname "kernel"))
              (symlink "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile" "kernel")))


Without your patch I get a
/gnu/store/c74g6pazpx9z5c1jkfi4rn8h42lf36dy-system-builder with only
one "kernel":

(begin (use-modules (guix build utils))
       (mkdir ((@ (guile) getenv) "out"))
       (chdir ((@ (guile) getenv) "out"))
       (begin (stat "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile")
              (mkdir-p (dirname "kernel"))
              (symlink "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile" "kernel"))
       (begin (stat "/gnu/store/7wjapypmzz4n93rwrnrrqwalwg8hhh3h-parameters")
              (mkdir-p (dirname "parameters"))
              (symlink "/gnu/store/7wjapypmzz4n93rwrnrrqwalwg8hhh3h-parameters" "parameters"))
       (begin (stat "/gnu/store/j27l3k8zjg9gn9j04y90gsjrqsryjapw-raw-initrd/initrd.cpio.gz")
              (mkdir-p (dirname "initrd"))
              (symlink "/gnu/store/j27l3k8zjg9gn9j04y90gsjrqsryjapw-raw-initrd/initrd.cpio.gz" "initrd"))
       (begin (stat "/gnu/store/bhnyk7bpzlzna28njkx21dd3940m1m4a-locale-multiple-versions")
              (mkdir-p (dirname "locale"))
              (symlink "/gnu/store/bhnyk7bpzlzna28njkx21dd3940m1m4a-locale-multiple-versions" "locale"))
       (begin (stat "/gnu/store/24irabcnv3pn2mpx4cjrggmlvn30k053-profile")
              (mkdir-p (dirname "profile"))
              (symlink "/gnu/store/24irabcnv3pn2mpx4cjrggmlvn30k053-profile" "profile"))
       (begin (stat "/gnu/store/z9jm8d8rrrpq19y1pmahpp73ja5ydw6h-etc")
              (mkdir-p (dirname "etc"))
              (symlink "/gnu/store/z9jm8d8rrrpq19y1pmahpp73ja5ydw6h-etc" "etc"))
       (begin (stat "/gnu/store/w90vvv7mx8g17i6frd34yvmbfi0nhnl1-boot")
              (mkdir-p (dirname "boot"))
              (symlink "/gnu/store/w90vvv7mx8g17i6frd34yvmbfi0nhnl1-boot" "boot")))

The diff is only the three lines at the bottom

(begin (stat "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile")
       (mkdir-p (dirname "kernel"))
       (symlink "/gnu/store/x22lj7pv64cg58dlwsg1q1srqawjbahi-profile" "kernel")))

Regards,
Florian
diff mbox series

Patch

diff --git a/gnu/services.scm b/gnu/services.scm
index f6dc56d940..b5ec222207 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -2,6 +2,7 @@ 
 ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -30,9 +31,11 @@ 
   #:use-module (guix describe)
   #:use-module (guix sets)
   #:use-module (guix ui)
-  #:use-module ((guix utils) #:select (source-properties->location))
+  #:use-module ((guix utils) #:select (source-properties->location
+                                       substitute-keyword-arguments))
   #:autoload   (guix openpgp) (openpgp-format-fingerprint)
   #:use-module (guix modules)
+  #:use-module (guix packages)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages hurd)
@@ -105,6 +108,12 @@ 
             firmware-service-type
             gc-root-service-type
 
+            kernel-profile-configuration
+            kernel-profile-configuration?
+            kernel-profile-configuration-kernel
+            kernel-profile-configuration-packages
+            kernel-profile-service-type
+
             %boot-service
             %activation-service
             etc-service))
@@ -474,6 +483,61 @@  channels in use and CONFIG-FILE, if it is true."
 itself: the channels used when building the system, and its configuration
 file, when available.")))
 
+
+;;;
+;;; Kernel profile.
+;;;
+
+(define-record-type* <kernel-profile-configuration>
+  kernel-profile-configuration make-kernel-profile-configuration
+  kernel-profile-configuration?
+  (kernel   kernel-profile-configuration-kernel)   ; <package>
+  (packages kernel-profile-configuration-packages  ; list of <package>
+            (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-profile-configuration->profile-entry config)
+  "Return a system entry for the kernel profile CONFIG."
+  (let* ((kernel (kernel-profile-configuration-kernel config))
+         (packages (map (lambda (package)
+                          (if (package? package)
+                              (package-for-kernel kernel
+                                                  package)
+                              package))
+                        (kernel-profile-configuration-packages config))))
+    (with-monad %store-monad
+      (return `(("kernel"
+                 ,(profile
+                   (content (packages->manifest
+                             (cons kernel
+                                   (delete-duplicates packages eq?))))
+                   (hooks (list linux-module-database)))))))))
+
+(define kernel-profile-service-type
+  (service-type (name 'kernel-profile)
+                (description "This is the @dfn{kernel profile}, available as
+@file{/run/current-system/kernel}.")
+                (extensions
+                 (list (service-extension
+                        system-service-type
+                        kernel-profile-configuration->profile-entry)))
+                (compose concatenate)
+                (extend (lambda (config additional-packages)
+                          (match-record config <kernel-profile-configuration>
+                            (kernel packages)
+                            (kernel-profile-configuration
+                             (kernel kernel)   ;the kernel package to use
+                             (packages (append packages additional-packages))))))))
+
 
 ;;;
 ;;; Cleanup.
diff --git a/gnu/system.scm b/gnu/system.scm
index bfbcb6fbdd..ff374dddda 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -511,16 +511,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 <https://bugs.gnu.org/35574>
@@ -574,6 +564,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)
+           (service kernel-profile-service-type
+                    (kernel-profile-configuration
+                     (kernel (operating-system-kernel os))
+                     (packages (operating-system-kernel-loadable-modules os))))
            %boot-service
 
            ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that
diff --git a/gnu/tests/linux-modules.scm b/gnu/tests/linux-modules.scm
index 953b132ef7..22e9a0c65c 100644
--- a/gnu/tests/linux-modules.scm
+++ b/gnu/tests/linux-modules.scm
@@ -73,10 +73,12 @@  are loaded in memory."
     (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))
+      (services (cons* (service kernel-module-loader-service-type module-names)
+                       (simple-service 'kernel-module-packages
+                                       kernel-profile-service-type
+                                       module-packages)
+                       (operating-system-user-services
+                        (simple-operating-system)))))
      #:imported-modules '((guix combinators))))
   (define vm (virtual-machine os))
   (define (test script)