diff mbox

[WIP] linux-initrd: Allow own set of kernel modules.

Message ID 20160728104224.10523-1-sleep_walker@gnu.org
State New
Headers show

Commit Message

Tomáš Čech July 28, 2016, 10:42 a.m. UTC
* gnu/system/linux-initrd.scm(base-initrd): Add `linux-modules'
  parameter. Rename former `linux-modules' to
  `default-linux-modules'. Introduce used-linux-modules to make the code
  more readable.
---
 gnu/system/linux-initrd.scm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Ludovic Courtès July 28, 2016, 1:05 p.m. UTC | #1
Tomáš Čech <sleep_walker@gnu.org> skribis:

> * gnu/system/linux-initrd.scm(base-initrd): Add `linux-modules'
>   parameter. Rename former `linux-modules' to
>   `default-linux-modules'. Introduce used-linux-modules to make the code
>   more readable.
> ---
>  gnu/system/linux-initrd.scm | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
> index bbaa5c0..4934c92 100644
> --- a/gnu/system/linux-initrd.scm
> +++ b/gnu/system/linux-initrd.scm
> @@ -138,6 +138,7 @@ MODULES and taken from LINUX."
>                        qemu-networking?
>                        (virtio? #t)
>                        volatile-root?
> +                      (linux-modules #f)
>                        (extra-modules '()))
>    "Return a monadic derivation that builds a generic initrd, with kernel
>  modules taken from LINUX.  FILE-SYSTEMS is a list of file-systems to be

It seems to serve the same purpose as #:extra-modules, no?

  https://www.gnu.org/software/guix/manual/html_node/Initial-RAM-Disk.html

Ludo’.
Tomáš Čech July 28, 2016, 1:35 p.m. UTC | #2
On Thu, Jul 28, 2016 at 03:05:34PM +0200, Ludovic Courtès wrote:
>Tomáš Čech <sleep_walker@gnu.org> skribis:
>
>> * gnu/system/linux-initrd.scm(base-initrd): Add `linux-modules'
>>   parameter. Rename former `linux-modules' to
>>   `default-linux-modules'. Introduce used-linux-modules to make the code
>>   more readable.
>> ---
>>  gnu/system/linux-initrd.scm | 12 +++++++++---
>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
>> index bbaa5c0..4934c92 100644
>> --- a/gnu/system/linux-initrd.scm
>> +++ b/gnu/system/linux-initrd.scm
>> @@ -138,6 +138,7 @@ MODULES and taken from LINUX."
>>                        qemu-networking?
>>                        (virtio? #t)
>>                        volatile-root?
>> +                      (linux-modules #f)
>>                        (extra-modules '()))
>>    "Return a monadic derivation that builds a generic initrd, with kernel
>>  modules taken from LINUX.  FILE-SYSTEMS is a list of file-systems to be
>
>It seems to serve the same purpose as #:extra-modules, no?
>
>  https://www.gnu.org/software/guix/manual/html_node/Initial-RAM-Disk.html

It gives me full control over the modules and not just appending to default set.

  #f --> default-kernel-modules (as it is now)
  '(some extraordinary special modules for other purpose) --> it will use this set
  '() --> it will use no module at all (my typical usecase)


But yes, it makes `extra-modules' useless.

I'd like to find a way, how to make default-kernel-modules available
as some lazy evaluated list (because what will go there is decided
when base-initrd is evaluated).

This is one of the steps for user defined kernel (besides specifying
kernel configuration) and I'm using it already.

If you're not against such change, it also would need to adjust
documentation (will do in next round).


S_W
Ludovic Courtès July 28, 2016, 3:32 p.m. UTC | #3
Tomáš Čech <sleep_walker@gnu.org> skribis:

> On Thu, Jul 28, 2016 at 03:05:34PM +0200, Ludovic Courtès wrote:
>>Tomáš Čech <sleep_walker@gnu.org> skribis:
>>
>>> * gnu/system/linux-initrd.scm(base-initrd): Add `linux-modules'
>>>   parameter. Rename former `linux-modules' to
>>>   `default-linux-modules'. Introduce used-linux-modules to make the code
>>>   more readable.
>>> ---
>>>  gnu/system/linux-initrd.scm | 12 +++++++++---
>>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
>>> index bbaa5c0..4934c92 100644
>>> --- a/gnu/system/linux-initrd.scm
>>> +++ b/gnu/system/linux-initrd.scm
>>> @@ -138,6 +138,7 @@ MODULES and taken from LINUX."
>>>                        qemu-networking?
>>>                        (virtio? #t)
>>>                        volatile-root?
>>> +                      (linux-modules #f)
>>>                        (extra-modules '()))
>>>    "Return a monadic derivation that builds a generic initrd, with kernel
>>>  modules taken from LINUX.  FILE-SYSTEMS is a list of file-systems to be
>>
>>It seems to serve the same purpose as #:extra-modules, no?
>>
>>  https://www.gnu.org/software/guix/manual/html_node/Initial-RAM-Disk.html
>
> It gives me full control over the modules and not just appending to default set.
>
>  #f --> default-kernel-modules (as it is now)
>  '(some extraordinary special modules for other purpose) --> it will use this set
>  '() --> it will use no module at all (my typical usecase)

Oh, OK.  I had assumed that the last use case didn’t exist ;-), which is
why we have #:extra-modules instead of just #:modules.

> But yes, it makes `extra-modules' useless.
>
> I'd like to find a way, how to make default-kernel-modules available
> as some lazy evaluated list (because what will go there is decided
> when base-initrd is evaluated).

What about this: instead of adding #:linux-modules to ‘base-initrd’,
let’s split ‘base-initrd’ into two procedures:

  1. ‘raw-initrd’ wouldn’t do anything high-level and wouldn’t try to
     guess what modules are needed;

  2. ‘base-initrd’ would keep the interface it currently has, but would
     be rewritten in terms of ‘raw-initrd’:

       (define (base-initrd …)
         ;; …
         (raw-initrd file-system
                     #:linux-modules the-full-list-of-modules))

How does that sound?

Ludo’.
Tobias Geerinckx-Rice July 28, 2016, 4:53 p.m. UTC | #4
Hullo,

On 28/07/2016 17:32, Ludovic Courtès wrote:
> Tomáš Čech <sleep_walker@gnu.org> skribis:
>>  #f --> default-kernel-modules (as it is now)
>>  '(some extraordinary special modules for other purpose) --> it will use this set
>>  '() --> it will use no module at all (my typical usecase)
> 
> Oh, OK.  I had assumed that the last use case didn’t exist ;-), which is
> why we have #:extra-modules instead of just #:modules.

How could anyone not want PATA support in their kernel? ;-)

Thanks, Tomáš! I had a similar patch ready, but it still tiptoed about
to keep #:extra-modules around. This is much nicer.

Kind regards,

T G-R
Alex Kost July 30, 2016, 3:38 p.m. UTC | #5
Tomáš Čech (2016-07-28 13:42 +0300) wrote:

> +  (define used-linux-modules
> +    (if (equal? linux-modules #f)
> +        default-linux-modules
> +        linux-modules))

Just a general note about the code.  This can simply be:

  (define used-linux-modules (or linux-modules default-linux-modules))
diff mbox

Patch

diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index bbaa5c0..4934c92 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -138,6 +138,7 @@  MODULES and taken from LINUX."
                       qemu-networking?
                       (virtio? #t)
                       volatile-root?
+                      (linux-modules #f)
                       (extra-modules '()))
   "Return a monadic derivation that builds a generic initrd, with kernel
 modules taken from LINUX.  FILE-SYSTEMS is a list of file-systems to be
@@ -174,7 +175,7 @@  loaded at boot time in the order in which they appear."
     (lambda (fs)
       (string=? (file-system-type fs) type)))
 
-  (define linux-modules
+  (define default-linux-modules
     ;; Modules added to the initrd and loaded from the initrd.
     `("ahci"                                  ;for SATA controllers
       "usb-storage" "uas"                     ;for the installation image etc.
@@ -220,8 +221,13 @@  loaded at boot time in the order in which they appear."
              (open source target)))
          mapped-devices))
 
+  (define used-linux-modules
+    (if (equal? linux-modules #f)
+        default-linux-modules
+        linux-modules))
+
   (mlet %store-monad ((kodir (flat-linux-module-directory linux
-                                                          linux-modules)))
+                                                          used-linux-modules)))
     (expression->initrd
      (with-imported-modules '((guix build bournish)
                               (guix build utils)
@@ -251,7 +257,7 @@  loaded at boot time in the order in which they appear."
            (boot-system #:mounts '#$(map file-system->spec file-systems)
                         #:pre-mount (lambda ()
                                       (and #$@device-mapping-commands))
-                        #:linux-modules '#$linux-modules
+                        #:linux-modules '#$used-linux-modules
                         #:linux-module-directory '#$kodir
                         #:qemu-guest-networking? #$qemu-networking?
                         #:volatile-root? '#$volatile-root?)))